iOS 中UIAlertView 的简单使用
来源:互联网 发布:大专程序员 编辑:程序博客网 时间:2024/05/14 23:35
iOS 中UIAlertView 的简单使用
1.创建
1.普通样式
NSString *title = @"我是标题"; // 标题 NSString *msg = @"你好"; // 你要显示的信息 NSString *cancel = @"取消"; // 取消键的标题 点击后 alertView会消失 NSString *other = @"其他:请点击"; // 其他按钮的标题,可以填写多个 // 这里主要不要把nil丢了,这是结束标志 // 设置了代理为self后要遵守UIAlertViewDelegate协议 UIAlertView *alerView = [[UIAlertView alloc] initWithTitle:title message:msg delegate:self cancelButtonTitle:cancel otherButtonTitles:other, nil]; [alerView show]; // 这里是通过modal方式弹出
显示的样式就是这样了
如果需要添加多个选项按钮
可以通过创建
[alerView addButtonWithTitle:@"其他:1"];
添加多个选项按钮后 样式也会改变
也可以通过如下方法添加多个选项按钮
UIAlertView的选项按钮尽量不要设置太多
一到两个既是理想
若想要设置更多的按钮可以通过UIActionSheet来实现
NSString *title = @"我是标题"; // 标题 NSString *msg = @"你好"; // 你要显示的信息 NSString *cancel = @"取消"; // 取消键的标题 点击后 alertView会消失 NSString *other = @"其他:请点击"; // 其他按钮的标题,可以填写多个 NSString *other1 = @"其他1:请点击"; NSString *other2 = @"其他2:请点击"; UIAlertView *alerView = [[UIAlertView alloc] initWithTitle:title message:msg delegate:self cancelButtonTitle:cancel otherButtonTitles:other,other1,other2, nil]; [alerView show];
如果添加按钮的标题过长
[alerView addButtonWithTitle:@"其他:过长过长过长过长过长过长过长过长过长过长过长过长过长过长过长过长"];
2.带输入框的样式
可以通过设置alertView的style设置样式
分别对应如下样式
alerView.alertViewStyle = UIAlertViewStylePlainTextInput;
UIAlertViewStylePlainTextInput这种是输入普通的文字
alerView.alertViewStyle = UIAlertViewStyleSecureTextInput;
UIAlertViewStyleSecureTextInput这种是输入密码的样式
alerView.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
UIAlertViewStyleLoginAndPasswordInput这种是输入登陆账号密码的样式
2.代理方法
可以通过下面方法取出对应按钮执行方法,响应用户的操作
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ NSLog(@"点击了第%zi个按钮",buttonIndex);}
如果控制器控制多个UIAlertView,那么回调方法可以通过设置alertView的tag来区别不同的UIAlertView.
用switch语句来对不同的UIAlertView进行响应
0 0
- iOS 中UIAlertView 的简单使用
- Swift UIAlertView 的简单使用
- iOS中UIAlertView的使用方法
- IOS开发之UIAlertView的简单应用
- swift中UIAlertView的使用
- swift中UIAlertView的使用
- UIAlertView弹出框的简单使用
- iOS中UIAlertView的点击响应事件
- ios学习笔记:UIAlertView的使用
- iOS开发:UIAlertView使用的问题
- 关于ios 中 UIAlertView
- iOS UIAlertView使用注意事项
- IOS开发:UIAlertView使用
- IOS开发:UIAlertView使用
- IOS开发:UIAlertView使用
- IOS开发:UIAlertView使用
- ios UIAlertView 使用
- ios中UIAlertView控件的使用,如何确定点击按钮的方式
- 数据结构与算法设计(读书笔记):2.算法分析
- 记录一次并未读源码调试程序的经历
- Android中View的事件体系(1)——坐标体系与移动
- 初试ASP.NET5 & MVC6 发布错误
- 八大排序算法之直接插入排序
- iOS 中UIAlertView 的简单使用
- JFrame实现无边框 及 实现拖动和Button关闭功能
- 采集侠的自动crontab脚本
- Android设计模式应用-桥接模式
- HDU - 5655 CA Loves Stick
- Bit manipulation
- Linux Shell笔记
- C#的数据类型简介
- 杭电2700