UIAlert
转自:https://blog.csdn.net/deng0zhaotai/article/details/53887508
通过uialertcontroller实现三种简易弹框
(一)警告类
- - (IBAction)showAlert:(UIButton *)sender {
- //显示提示框
- //过时
- // UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"message" delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:@"ok", nil];
- // [alert show];
- UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Title"
- message:@"This is an alert."
- preferredStyle:UIAlertControllerStyleAlert];
- UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
- handler:^(UIAlertAction * action) {
- //响应事件
- NSLog(@"action = %@", action);
- }];
- UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault
- handler:^(UIAlertAction * action) {
- //响应事件
- NSLog(@"action = %@", action);
- }];
- [alert addAction:defaultAction];
- [alert addAction:cancelAction];
- [self presentViewController:alert animated:YES completion:nil];
- }
(二)带输入框警告类
- - (IBAction)showList:(UIButton *)sender {
- //提示框添加文本输入框
- UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Title"
- message:@"This is an alert."
- preferredStyle:UIAlertControllerStyleAlert];
- UIAlertAction* okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault
- handler:^(UIAlertAction * action) {
- //响应事件
- //得到文本信息
- for(UITextField *text in alert.textFields){
- NSLog(@"text = %@", text.text);
- }
- }];
- UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel
- handler:^(UIAlertAction * action) {
- //响应事件
- NSLog(@"action = %@", alert.textFields);
- }];
- [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
- textField.placeholder = @"登录";
- }];
- [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
- textField.placeholder = @"密码";
- textField.secureTextEntry = YES;
- }];
- [alert addAction:okAction];
- [alert addAction:cancelAction];
- [self presentViewController:alert animated:YES completion:nil];
- }
(三)操作列表类
- - (IBAction)showSheet:(UIButton *)sender {
- //显示弹出框列表选择
- UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Title"
- message:@"This is an Sheet."
- preferredStyle:UIAlertControllerStyleActionSheet];
- UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel
- handler:^(UIAlertAction * action) {
- //响应事件
- NSLog(@"action = %@", action);
- }];
- UIAlertAction* deleteAction = [UIAlertAction actionWithTitle:@"删除" style:UIAlertActionStyleDestructive
- handler:^(UIAlertAction * action) {
- //响应事件
- NSLog(@"action = %@", action);
- }];
- UIAlertAction* saveAction = [UIAlertAction actionWithTitle:@"保存" style:UIAlertActionStyleDefault
- handler:^(UIAlertAction * action) {
- //响应事件
- NSLog(@"action = %@", action);
- }];
- [alert addAction:saveAction];
- [alert addAction:cancelAction];
- [alert addAction:deleteAction];
- [self presentViewController:alert animated:YES completion:nil];
- }
UIAlert的更多相关文章
- UIAlertView' is deprecated: first deprecated in iOS 9.0 - UIAlertView is deprecated. Use UIAlert
UIAlertController * cancleAlertController = [UIAlertController alertControllerWithTitle:nil message: ...
- [IOS UIalert模版]
1.alertview创建 UIAlertView *alert; alert = [[UIAlertView alloc] initWithTitle:@"提示" message ...
- UIActionSheet和UIAlert
UIActionSheet: 首先,在.h文件中添加Protocol,(Protocol相当于Java中的interface) @interface ActionSheetViewController ...
- UIkit框架之UIalert(iOS 9之后就不用这个了)
IOS中UIAlertView(警告框)常用方法总结 一.初始化方法 - (instancetype)initWithTitle:(NSString *)title message:(NSString ...
- 【iOS开发-56】案例BUG:button的enabled、控件的userInteractionEnabled以及两种提示框UIAlert和UIActionSheet
接上述案例找BUG:[iOS开发-51]案例学习:动画新写法.删除子视图.视图顺序.延迟方法.button多功能使用方法及icon图标和启动页设置 (1)BUG:答案满了就不能再点击optionbut ...
- IOS之UIAlertController
你知道 UIAlertView.UIActionSheet (以及它们各自的 delegate protocols) 在 iOS 8 中已经被废弃了吗? 这是真的.在你的代码中按住 ⌘ 点击 UIAl ...
- iOS开发系列--视图切换
概述 在iOS开发中视图的切换是很频繁的,独立的视图应用在实际开发过程中并不常见,除非你的应用足够简单.在iOS开发中常用的视图切换有三种,今天我们将一一介绍: UITabBarController ...
- iOS开发——高级篇——iOS中常见的设计模式(MVC/单例/委托/观察者)
关于设计模式这个问题,在网上也找过一些资料,下面是我自己总结的,分享给大家 如果你刚接触设计模式,我们有好消息告诉你!首先,多亏了Cocoa的构建方式,你已经使用了许多的设计模式以及被鼓励的最佳实践. ...
- IOS要用到的东西
code4app.com 这网站不错,收集各种 iOS App 开发可以用到的代码示例 cocoacontrols.com/ 英文版本的lib收集 objclibs.com/ 精品lib的收集网站 h ...
随机推荐
- hihttps教你在Wireshark中提取旁路https解密源码
大家好,我是hihttps,专注SSL web安全研究,今天本文就是教大家怎样从wireshark源码中,提取旁路https解密的源码,非常值得学习和商业应用. 一.旁路https解密条件 众所周知, ...
- 一个有意思的js块作用域问题
1.问题 首先把问题放出来,昨天看了一个掘友发的一个问题,然后跟我同事一起研究了一下,没找出来是为什么,然后我回来一直在想为什么,然后各种找资料研究,从各个方面找为什么,比如js上下文,作用域,js垃 ...
- java8 base64使用
java 1.8中引入了Base64,不在需要引入第三方库就可以使用base64了. 在需要用到base64进行加密解密的时候就可以使用了 String text = "base64 in ...
- Object.keys方法详解
一.官方解释 Object.keys() 方法会返回一个由一个给定对象的自身可枚举属性组成的数组,数组中属性名的排列顺序和使用 for...in 循环遍历该对象时返回的顺序一致 .如果对象的键-值都不 ...
- linux下安装配置go语言环境
1,golang中国下载go源码 http://www.golangtc.com/download 请对应系统版本号,linux-amd64.tar.gz为64位系统(推荐) ,linux-386 ...
- el-table实现行列拖拽
element ui 表格没有自带的拖拽排序的功能,只能借助第三方插件Sortablejs来实现. 实现步骤: 安装Sortable.js npm install sortablejs --save ...
- springboot项目目录结构
idea新建springboot项目 按默认下一步至完成,默认目录结构如下 pom.xml文件内容如下 <?xml version="1.0" encoding=" ...
- Coins POJ - 1742
给出硬币面额及每种硬币的个数,求从1到m能凑出面额的个数. Input 多组数据,每组数据前两个数字为n,m.n表示硬币种类数,m为最大面额,之后前n个数为每种硬币的面额,后n个数为相应每种硬币的个数 ...
- bugku 各种·绕过
点开是一段PHP的代码,先来审计一波代码. 发现将uname和passwd用sha1进行了加密,那么我们只要绕过这个函数构造相等就可以了. 可以使这两个值sha1的值相等,但他们本身的值又不等.(想详 ...
- 一个神秘现象引发对beego框架的思考
小强最近在项目中遇到了一个很奇怪的问题:在整改日志规范时,为了避免影响现有的代码结构以及改动尽可能小的前提下,在调用记日志的SDK处将某一个字段值首字母改为大写,代码示例如下: fmt.Println ...