- (void)viewDidLoad {
[super viewDidLoad];
UIButton *alertBtn = [UIButton buttonWithType:UIButtonTypeSystem];
alertBtn.frame = CGRectMake(40, 100, 295, 30);
[alertBtn setTitle:@"Show AlertController" forState:UIControlStateNormal];
[alertBtn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:alertBtn];
}
- (void)btnClicked:(UIButton *)btn
{
// UIAlertControllerStyleActionSheet ActionSheet的样式
// UIAlertControllerStyleAlert AlertView的样式
// 实例化UIAlertController,这个东西是iOS8才有的
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"这是一个AlertController" message:@"这里是提示的内容" preferredStyle:UIAlertControllerStyleActionSheet];
// 创建3个按钮
UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"按钮1" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
NSLog(@"点击了按钮1");
}];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消按钮" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
NSLog(@"点击了取消按钮");
}];
UIAlertAction *deleteAction = [UIAlertAction actionWithTitle:@"删除按钮" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
NSLog(@"点击了删除按钮");
}];
// 把按钮添加到AlertController里面
[alertController addAction:action1];
[alertController addAction:cancelAction];
[alertController addAction:deleteAction];
// 显示AlertController,用模式跳转的方式让其显示
[self presentViewController:alertController animated:YES completion:^{
}];
}
相关文章
- Struts2第十一篇【简单UI标签、数据回显】
- 第十四节:SQLServer触发器详解(概述、工作原理、应用)
- Objective-c——UI基础开发第十二天(相册展示)
- UI第十五节——UIWebView
- UI学习笔记---第十二天UITabBarController
- 大白话5分钟带你走进人工智能-第十四节过拟合解决手段L1和L2正则
- ASP.NET MVC深入浅出(被替换) 第一节: 结合EF的本地缓存属性来介绍【EF增删改操作】的几种形式 第三节: EF调用普通SQL语句的两类封装(ExecuteSqlCommand和SqlQuery ) 第四节: EF调用存储过程的通用写法和DBFirst模式子类调用的特有写法 第六节: EF高级属性(二) 之延迟加载、立即加载、显示加载(含导航属性) 第十节: EF的三种追踪
- UI第十四节——UIAlertController
- 《linux就该这么学》第十四节课:第13章,部署DNS域名解析服务(bind服务)
- Android UI开发第十五篇——分享一个登录缓冲界面