IOS开发(1)之UIAlertView
来源:互联网 发布:ae mac 中文 编辑:程序博客网 时间:2024/04/28 22:19
1.前言
之前简单的学习了Objective-C的基础语法,从今天起我们开始学习简单的IOS视图开发。
2.UIAlertView入门
2.1普通弹框
使用提示视图的最好方法,当然是使用特定的初始化方法:
- (void)viewDidLoad{ [super viewDidLoad];// Do any additional setup after loading the view, typically from a nib. //Title:这个字符串会显示在提示视图的最上面的Title。 UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Title" //message:这是要给用户看的实际讯息。 message:@"Message" //delegate:我们可以传递委托对象(可选)给提示视图。当视图状态变更时,委托对象会被通知。传递的参数对象必须实践UIAlertViewDelegate协定. delegate:nil //cancelButtonTitle:可选参数。这个字符串符会显示在提示视图的取消按钮上。通常有取消按钮的提示视图都是要要求用户做确认,用户若不愿意进行该动作,就会按下取消。这个按钮的的标是可以自行设定的,不一定会显示取消。 cancelButtonTitle:@"Cancel" //otherButtonTitles:可选参数。若你希望提示视图出现其他按钮,只要传递标题参数。此参数需用逗号分隔,用 nil 做结尾。 otherButtonTitles:@"Ok", nil]; [alertView show];}
运行结果:
2.2代理弹框
.h文件:
@interface ZYAlertYesOrNoViewController : UIViewController<UIAlertViewDelegate>//增加UIAlertViewDelegate代理-(void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;@end.m文件:
- (void)viewDidAppear:(BOOL)animated{ [super viewDidAppear:animated]; //初始化UIAlertView self.view.backgroundColor = [UIColor whiteColor]; UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Rating" message:@"Can you please rate our app?" //为自身添加代理 delegate:self cancelButtonTitle:[self noButtonTitle] otherButtonTitles:[self yesButtonTitle], nil]; [alertView show];}
- (NSString *) yesButtonTitle{ return @"Yes";}- (NSString *) noButtonTitle{ return @"No";}//判断用户按下的是Yes还是No-(void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ NSString *buttonTitle = [alertView buttonTitleAtIndex:buttonIndex]; if ([buttonTitle isEqualToString:[self yesButtonTitle]]) { NSLog(@"User pressed the Yes button."); }else if([buttonTitle isEqualToString:[self noButtonTitle]]){ NSLog(@"User pressed the No button."); }}
当点击Yes按钮后
运行结果(控制台显示):
2013-04-22 11:21:33.675 UIAlertViewTestDemo[1147:c07] User pressed the Yes button.
2.3带输入框的Alert
//登陆弹出框:一个文本输入框,一个密码框UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Password" message:@"Please enter your credentials" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];//设置AlertView的样式[alertView setAlertViewStyle:UIAlertViewStyleLoginAndPasswordInput];[alertView show];
运行结果:
UIAlertView样式:
type enum{UIAlertViewStyleDefalut=0;//默认样式UIAlertViewStyleSecureTextInput,//密码框UIAlertViewStylePlainTextInput,//文本输入框UIAlertViewStyleLoginAndPasswordInput //有登陆效果的提示框}UIAlertViewStyle
3.结语
对于UIAlertView控件,就介绍这么多了,希望对大家有所帮助。
Demo例子下载地址:http://download.csdn.net/detail/u010013695/5286596
- IOS开发(1)之UIAlertView
- IOS开发(1)之UIAlertView
- iOS开发之UIalertView
- 【学习笔记】IOS(1)之UIAlertView
- iOS开发之如何自定义UIActionSheet(UIAlertView)中的内容
- ios开发之改变UIAlertView背景图片
- iOS开发之UIAlertview的事件处理
- IOS开发之UIAlertView的简单应用
- IOS开发之delegate,NSTimer,UIAlertView
- iOS开发之 UIAlertView 沙盒 归档
- UIAlertView警报-IOS开发
- IOS开发:UIAlertView使用
- iOS开发-UIAlertView
- IOS开发:UIAlertView使用
- IOS开发:UIAlertView使用
- iOS开发:UIAlertView
- IOS开发:UIAlertView使用
- iOS之UIAlertView
- hdu3555——Bomb(数位DP)
- HDOJ 2955 Robberies (0/1背包)
- uboot makefile分析
- 解决httpclient传中文乱码问题
- modelsim的 # (vish-4014) No objects found matching '/*'
- IOS开发(1)之UIAlertView
- Android 使用HttpClient和第三方MiME文件上传类库,实现文件上传带进度条
- 关于java的++和--操作符,你真的搞明白了吗?
- jvm-栈与堆区别
- 不上大学,你可以学些什么?
- hdu 1284 钱币兑换问题
- UVA 10943全加和(规律)
- 嗯我决定学习一下searchable,一个基于grails的plugin
- 黑马程序员_怎样让VirtualBox虚拟机既可以上网又可以和主机通信