從零開(kāi)始iOS8編程【iOS開(kāi)發(fā)常用控件】
來(lái)源:程序員人生 發(fā)布時(shí)間:2014-12-13 09:17:02 閱讀次數(shù):2771次
郝萌主傾心貢獻(xiàn),尊重作者的勞動(dòng)成果,請(qǐng)勿轉(zhuǎn)載。
如果文章對(duì)您有所幫助,歡迎給作者捐贈(zèng),支持郝萌主,捐贈(zèng)數(shù)額隨便,重在情意^_^
我要捐贈(zèng): 點(diǎn)擊捐贈(zèng)
Cocos2d-X源碼下載:點(diǎn)我傳送
AlertView控件
彈出對(duì)話框:
修改HelloHaoMengZhu項(xiàng)目代碼, 添加AlertView:
-(IBAction)testAlert {
NSString *str = [[NSString alloc] initWithFormat:@"Hello, %@",txtField.text];
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"提示" message:str
delegate:self
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[str release];
[alert show];
[alert release];
}
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
NSLog(@"%@",@"Ok" );
}
ActionSheet控件
ActionSheet和AlertView比較相似都是給用戶1個(gè)提示信息。
它是從底部彈出。
它通經(jīng)常使用于確認(rèn)潛伏的危險(xiǎn)或不能撤銷的操作, 如刪除1個(gè)數(shù)據(jù)。
為了使用ActionSheet我們需要在h文件中實(shí)現(xiàn)UIActionSheetDelegate協(xié)議。
其中, 我們常常需要實(shí)現(xiàn):actionSheet:didDismissWithButtonIndex:
該方法是ActionSheet消失的時(shí)候調(diào)用。
修改Hello-.h文件
@interface HelloHaoMengZhuViewController : UIViewController
{
UITextField *txtField;
UIActivityIndicatorView * myActivityView;
IBOutlet UIProgressView *Progress;
NSTimer *timer;
}
在Hello_Controller.h文件中添加協(xié)議UIActionSheetDelegate:
-(IBAction)testActionSheet {
NSString *str = [[NSString alloc] initWithFormat:@"Hello, %@",txtField.text];
UIActionSheet *action = [[UIActionSheet alloc] initWithTitle:@"提示"
delegate:self
cancelButtonTitle:@"取消"
destructiveButtonTitle:@"肯定"
otherButtonTitles:nil];
[str release];
[action showInView:self.view];
[action release];
}
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex {
if (buttonIndex == [actionSheet destructiveButtonIndex]) {
NSLog(@"%@",@"肯定" );
} else if (buttonIndex == [actionSheet cancelButtonIndex]) {
NSLog(@"%@",@"取消" );
}
}
等待有關(guān)控件
對(duì)1些費(fèi)時(shí)的處理, 需要使用1些等待控件消除用戶心里等待的時(shí)間。
等待有關(guān)的控件有:
UIActivityIndicatorView
UIProgressView
設(shè)計(jì)UI:
UIActivityIndicatorView的實(shí)現(xiàn)

-(IBAction)onClickButton2: (id)sender {
if ([myActivityView isAnimating]) {
[myActivityView stopAnimating];
} else {
[myActivityView startAnimating];
}
}
UIProgressView的實(shí)現(xiàn)
-(IBAction)start{
Progress.progress = 0.0;
timer = [NSTimer
scheduledTimerWithTimeInterval:1.0
target:self
selector:@selector(update)
userInfo:nil repeats:YES];
}
代碼說(shuō)明:
NSTimer是可以隱式地啟動(dòng)1個(gè)線程,
scheduledTimerWithTimeInterval指定線程要休眠多少時(shí)間調(diào)用1次,
selector所指定的方法update。
-(void)update{
Progress.progress = Progress.progress + 0.1;
if (Progress.progress == 1.0) {
[timer invalidate];
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"任務(wù)通知"
message:@"波多野結(jié)衣.avi 下載完成!"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
}
代碼說(shuō)明:
UIProgressView控件的progress屬性是0.0~1.0煩范圍。
0.0時(shí)候在開(kāi)始的位置, 1.0時(shí)候是進(jìn)度到了100%。
郝萌主傾心貢獻(xiàn),尊重作者的勞動(dòng)成果,請(qǐng)勿轉(zhuǎn)載。
如果文章對(duì)您有所幫助,歡迎給作者捐贈(zèng),支持郝萌主,捐贈(zèng)數(shù)額隨便,重在情意^_^
我要捐贈(zèng): 點(diǎn)擊捐贈(zèng)
Cocos2d-X源碼下載:點(diǎn)我傳送
生活不易,碼農(nóng)辛苦
如果您覺(jué)得本網(wǎng)站對(duì)您的學(xué)習(xí)有所幫助,可以手機(jī)掃描二維碼進(jìn)行捐贈(zèng)