从零开始iOS8编程【iOS开发常用控件】

郝萌主倾心贡献,尊重作者的劳动成果,请勿转载。

如果文章对您有所帮助,欢迎给作者捐赠,支持郝萌主,捐赠数额随意,重在心意^_^ 

我要捐赠: 点击捐赠

Cocos2d-X×××:点我传送


AlertView控件
弹出对话框:
修改HelloHaoMengZhu项目代码, 添加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比较相似都是给用户一个提示信息。 
它是从底部弹出。
它通常用于确认潜在的危险或不能撤消的操作, 如删除一个数据。
为了使用ActionSheet我们需要在h文件中实现UIActionSheetDelegate协议。 
其中, 我们常常需要实现:actionSheet:didDismissWithButtonIndex:
该方法是ActionSheet消失的时候调用。

修改Hello-.h文件
@interface HelloHaoMengZhuViewController : UIViewController {     UITextField *txtField;     UIActivityIndicatorView * myActivityView;          IBOutlet UIProgressView *Progress; 	NSTimer *timer; }
在Hello_Controller.h文件中添加协议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(@"%@",@"取消" ); 	} } 


等待有关控件
对于一些费时的处理, 需要使用一些等待控件消除用户心里等待的时间。
等待有关的控件有:
UIActivityIndicatorView
UIProgressView

设计UI:


UIActivityIndicatorView的实现
-(IBAction)onClickButton2: (id)sender { 	if ([myActivityView isAnimating]) { 		[myActivityView stopAnimating]; 	} else { 		[myActivityView startAnimating]; 	} }


UIProgressView的实现
-(IBAction)start{ 	Progress.progress = 0.0; 	timer = [NSTimer 			 scheduledTimerWithTimeInterval:1.0 			 target:self 			 selector:@selector(update) 			 userInfo:nil repeats:YES]; }
代码说明:
NSTimer是可以隐式地启动一个线程
scheduledTimerWithTimeInterval指定线程要休眠多少时间调用一次, 
selector所指定的方法update。
-(void)update{ 	Progress.progress = Progress.progress + 0.1; 	if (Progress.progress == 1.0) { 		[timer invalidate]; 		UIAlertView *alert = [[UIAlertView alloc] 							  initWithTitle:@"任务通知" 							  message:@"波多野结衣.avi 下载完成!" 							  delegate:self 							  cancelButtonTitle:@"OK" 							  otherButtonTitles:nil]; 		[alert show]; 		[alert release]; 	} }
代码说明:
UIProgressView控件的progress属性是0.0~1.0烦范围。 
0.0时候在开始的位置, 1.0时候是进度到了100%。



郝萌主倾心贡献,尊重作者的劳动成果,请勿转载。

如果文章对您有所帮助,欢迎给作者捐赠,支持郝萌主,捐赠数额随意,重在心意^_^ 

我要捐赠: 点击捐赠

Cocos2d-X×××:点我传送


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章