UIAlertController
来源:互联网 发布:带数据统计的二维码 编辑:程序博客网 时间:2024/05/29 10:15
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"标题" message:@"2222" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil]; [alertView show];
//iOS8以后 UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"标题" message:@"2222222" preferredStyle:UIAlertControllerStyleAlert]; //添加按钮 [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]]; [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) { NSLog(@"点击了确定"); }]]; //显示控制器 [self presentViewController:alert animated:YES completion:nil];还可以换种样式:
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"标题" message:@"2222222" preferredStyle:UIAlertControllerStyleActionSheet]; //添加按钮 [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]]; [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) { NSLog(@"点击了确定"); }]]; //显示控制器 [self presentViewController:alert animated:YES completion:nil];还可以添加文本输入框:
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"标题" message:@"2222222" preferredStyle:UIAlertControllerStyleAlert]; //添加按钮 [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]]; [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {// NSLog(@"点击了确定"); //拿到文本输入框的值 NSString *name = [alert.textFields[0] text]; NSString *pwd = [alert.textFields[1] text]; NSLog(@"%@ %@",name,pwd); }]]; //还可以添加文本输入框 [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) { textField.placeholder = @"请输入用户名"; }]; [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) { textField.placeholder = @"请输入密码"; }]; //显示控制器 [self presentViewController:alert animated:YES completion:nil];
0 0
- UIAlertController
- UIAlertController
- UIAlertController
- UIAlertController
- UIAlertController
- UIalertController
- UIAlertController
- UIalertController
- UIAlertController
- UIAlertController
- UIAlertController
- UIAlertController
- UIAlertController
- UIAlertController
- UIAlertController
- UIAlertController
- UIAlertController
- UIAlertController
- Python 值传递和引用传递
- OC-4-语法总结
- MyEclipse里运行Tomcat后,Console窗口里中文显示乱码
- 【Java】javaIO之用随机流读写文件
- OC+1-内存管理
- UIAlertController
- OC+2-ARC-Category-block
- 微信内置浏览器音频直播
- OC+3-protocol
- Tomcat【4】(tomcat在eclipse的配置)
- rtsprecorder接收rtsp流并录像存档的调试过程
- HDU 2516 取石子游戏(fibonacci博弈)
- 【Java】javaIO之带缓冲流的字节流文件读写
- OC+4-Foundation框架