博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UIAlertController
阅读量:7126 次
发布时间:2019-06-28

本文共 3146 字,大约阅读时间需要 10 分钟。

1、alertController 的创建

// 1. 创建时不添加按钮// 实例化 alertController 对象UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"警告" message:@"真的要关闭 !" preferredStyle:UIAlertControllerStyleAlert];// 显示,模态视图显示[self presentViewController:alertController animated:YES completion:nil];// 2. 创建时添加按钮等信息// 实例化 UIAlertController 对象UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"警告" message:@"真的要关闭 !" preferredStyle:UIAlertControllerStyleAlert];// 创建按钮UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];UIAlertAction *noAction = [UIAlertAction actionWithTitle:@"考虑一下" style:UIAlertActionStyleDestructive handler:nil];// 向 alertController 上添加按钮[alertController addAction:cancelAction];[alertController addAction:okAction];[alertController addAction:noAction];// 显示 alertController 视图[self presentViewController:alertController animated:YES completion:nil];

2、alertController 的设置

// 设置警告框类型/*UIAlertControllerStyleActionSheet = 0,   上拉菜单,操作表,底部弹出UIAlertControllerStyleAlert              对话框,警告,中间弹出*/UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"警告" message:@"真的要关闭 ?" preferredStyle:UIAlertControllerStyleAlert];// 设置按钮类型/*UIAlertActionStyleDefault = 0,  默认蓝色按钮,可以有多个UIAlertActionStyleCancel,       取消按钮,显示在左侧或最下边,有且只能有一个UIAlertActionStyleDestructive   红色警示按钮,可以有多个,《iOS 用户界面指南》要求所有的 “警示” 样式按钮都必须排名第一*/UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];// 设置按钮点击响应事件UIAlertAction *closeAction = [UIAlertAction actionWithTitle:@"关闭" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {/*点击了按钮时响应的事件*/}];// 添加输入框/*只能添加到 UIAlertControllerStyleAlert 上,可以添加多个*/[alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {/*设置添加的 textField 属性*/}];// 添加点击按钮/* 添加警告框上的按钮,可以添加多个取消按钮在左侧或最下边,其它按钮按照添加的顺序排列*/[alertController addAction:cancelAction];// 设置首选按钮/*必须在添加按钮(addAction)完成后设置,iOS 9 新添加首选的按钮会有加粗效果,只能用在 UIAlertControllerStyleAlert 中*/alertController.preferredAction = okAction;// 设置按钮激活状态/*YES 按钮激活,可点击。NO 按钮禁用,不可点击*/okAction.enabled = YES;// 显示警告框视图[self presentViewController:alertController animated:YES completion:nil];// 设置警告框标题alertController.title = @"登录";// 设置警告框提示信息alertController.message = @"请输入用户名和密码登录 !";// 获取警告框标题NSString *alertTitle = alertController.title;// 获取警告框提示信息NSString *alertMessage = alertController.message;// 获取警告框类型,readonlyUIAlertControllerStyle alertStyle = alertController.preferredStyle;// 获取所有输入框,readonlyNSArray
*textFieldArray = alertController.textFields;// 获取所有按钮,readonlyNSArray
*actionsArray = alertController.actions;// 获取按钮标题,readonlyNSString *actionTitle = okAction.title;// 获取按钮类型,readonlyUIAlertActionStyle actionStyle = okAction.style;// 获取首选按钮UIAlertAction *preferredAction = alertController.preferredAction;// 获取按钮激活状态BOOL actionEnabled = okAction.enabled;

转载于:https://www.cnblogs.com/CH520/p/9413502.html

你可能感兴趣的文章
超强、超详细Redis数据库入门教程
查看>>
《C++语言基础》实践项目——多重继承
查看>>
京颐集团上云之路:如何助力中小型医疗行业信息化与全面上云?
查看>>
设计可以多选的按钮ChooseManyButton
查看>>
NSURLErrorDomain Code=-999
查看>>
SQL模板资源管理器,你用了吗?
查看>>
ORA-00600: internal error code, arguments: [17281], [1001], [0x1FF863EE8], [], [], [], [], []
查看>>
吃鸡数据不完全分析
查看>>
APK体积优化的一些总结
查看>>
介绍一款Java的方法入参校验工具
查看>>
不借助第三个变量交换 a,b两个值
查看>>
[深入SystemUI]-了解recents的启动流程(一)
查看>>
Android线程池的原理以及项目中实践
查看>>
声明 NSString 类型的属性,到底用 strong 还是 copy ?
查看>>
我的友情链接
查看>>
设置接口跨域调用方法
查看>>
python selenium系列(八)元素定位进阶之分层定位
查看>>
MySQL多表连接优化一例
查看>>
PHP动态扩展模块安装
查看>>
AgileEAS.NET平台开发实例-药店系统-UI层重构技巧及其他
查看>>