当前位置: 首页 > news >正文

iOS UIAlertController控件

ios 9 以后 UIAlertController取代UIAlertView和UIActionSheet

UIAlertControllerStyleAlert和UIAlertControllerStyleActionSheet。


在UIAlertController中添加按钮和关联输入框

UIAlertAction共有三种类型,默认(UIAlertActionStyleDefault)、取消(UIAlertActionStyleCancel)和警告(UIAlertActionStyleDestructive)。

- (void)addAction:(UIAlertAction *)action;
- (void)addTextFieldWithConfigurationHandler:(void (^ __nullable)(UITextField *textField))configurationHandler;

1. UIAlertControllerStyleAlert模式

UIAlertControllerStyleAlert模式会弹出一个对话框视图,点击其他区域不会退出。

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"标题" message:@"这是一个测试"preferredStyle:UIAlertControllerStyleAlert];
[alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {textField.placeholder = @"请输入";
}];
[alert addAction:[UIAlertAction actionWithTitle:@"默认" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){NSLog(@"text = %@", alert.textFields.firstObject.text);NSLog(@"默认按钮");
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action){NSLog(@"取消按钮");
}]];
[self presentViewController:alert animated:YES completion:^(){NSLog(@"alert completion");
}];

显示如下

在这里插入图片描述

 

2. UIAlertControllerStyleActionSheet模式

UIAlertControllerStyleActionSheet模式会从底部弹出一个视图,点击其他区域也会退出。

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"标题" message:@"这是一个测试"preferredStyle:UIAlertControllerStyleActionSheet];
[alert addAction:[UIAlertAction actionWithTitle:@"选项一" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){NSLog(@"按钮一");
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"选项二" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){NSLog(@"按钮二");
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action){NSLog(@"取消按钮");
}]];[self presentViewController:alert animated:YES completion:nil];

显示如下

在这里插入图片描述

 

http://www.lryc.cn/news/127234.html

相关文章:

  • C语言好题解析(二)
  • 数据结构介绍
  • Kafka基础及常见面试题
  • 基于Java的ssm图书管理系统源码和论文
  • 2020年9月全国计算机等级考试真题(C语言二级)
  • 【rust/egui】(一)从编译运行template开始
  • VMware虚拟安装Ubuntu,然后切换Ubuntu内核版本
  • 爆肝整理,Python自动化测试-Pytest参数化实战封装,一篇打通...
  • 西门子AI面试问答(STAR法则回答实例)
  • 中间平台工具 - graylog
  • VectorStyler for Mac: 让你的创意无限绽放的全新设计工具
  • 轻松转换TS视频为MP4,实现优质视频剪辑体验
  • IDEA关闭项目,但是后台程序没有关闭进程(解决方案)
  • github拉取自己的私有仓库(Token方式、本地秘钥方式)
  • 聊聊非科班转IT
  • NET域名的优势
  • ZLMediaKit推流测试
  • 高防服务器的防御机制
  • 【PySide】QtWebEngine网页浏览器打开Flash网页
  • 【力扣每日一题】1572. 矩阵对角线元素的和 8.11打卡
  • Wi-Fi 安全在学校中的重要性
  • 若依微服务集成CAS,实现单点登录
  • 解锁园区交通新模式:园区低速自动驾驶
  • SpringBoot-Hello World
  • 香港服务器三网直连内地线路什么意思?好用吗?
  • component:()=>import(“@/views/Home.vue“) 报错,ts说没有找到类型声明文件
  • 为什么hive会出现_HIVE_DEFAULT_PARTITION分区
  • 通讯协议041——全网独有的OPC HDA知识一之聚合(九)首值
  • opencv进阶01-直方图的应用及示例cv2.calcHist()
  • 网络通信原理TCP的四次断开连接(第四十九课)