从ios8之后,系统的弹框    UIAlertView 与  UIActionSheet 两个并在一了起, 使用了一个新的控制器叫 UIAlertController

UIAlertController的基本使用

创建UIAlertController

Title:显示的标题
message:标题底部显示的描述信息
preferredStyle:弹框的样式
样式分为两种:
UIAlertControllerStyleActionSheet:
UIAlertControllerStyleAlert 两种样式分别显示如下: 第一步:创建控制器
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"确定要退出嘛?" message:@“显示的信息" preferredStyle:UIAlertControllerStyleActionSheet]; 第二步:创建按钮
弹框当中的每一个按钮分别对应一个 UIAlertAction UIAlertAction创建方式如下:
actionWithTitle:按钮要显示的文字
style:按钮要显示的样式
样式分为三种:
UIAlertActionStyleDefault:默认样式,默认按钮颜色为蓝色
UIAlertActionStyleCancel:设置按钮为取消.点击取消是,会动退出弹框.
注意:取消样式只能设置一个,如果有多个取消样式,则会发生错误.
UIAlertActionStyleDestructive:危险操作按钮,按钮颜色显示为红公
handler:点击按钮时调用Block内部代码. UIAlertAction *action = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"点击了取消");
}]; UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"点击了取消");
[self.navigationController popViewControllerAnimated:YES];
}]; 第三步:添加按钮
把创建的UIAlertAction添加到控制器当中.
[alertController addAction:action];
[alertController addAction:action1]; 除了添加按钮之外,还可以添加文本框,
添加文本框的前提是UIAlertController的样式必须得要是UIAlertControllerStyleAlert样式.否则会直接报错
添加文本框方法为:
[alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.placeholder = @“文本框点位文字";
}]; 运行效果为: 通过控制器的textFields属性获取添加的文本框.注意textFields它是一个数组.
UITextField *textF = alertController.textFields.lastObject; 第四步:显示弹框.(相当于show操作)
[self presentViewController:alertController animated:YES completion:nil];

UIAlertController基本使用的更多相关文章

  1. UIAlertController

    楼主在整理项目的警告,于是乎你懂的. 然后自己整理了一下以后方便自己忘了之后能及时找到它 关于UIAlertController .h文件的解析 /** 关于UIAlertController的解析 ...

  2. iOS UIAlertController跟AlertView用法一样 && otherButtonTitles:(nullable NSString *)otherButtonTitles, ... 写法

    今天写弹出框UIAlertController,用alertView习惯了,所以封装了一下,跟alertView用法一样,不说了,直接上代码: 先来了解一下otherButtonTitles:(nul ...

  3. UIAlertController使用

    // 将UIAlertController模态出来 相当于UIAlertView show 的方法// 初始化一个一个UIAlertController    // 参数preferredStyle: ...

  4. IOS UIAlertController 使用方法

    在很多种语言中,alert都表示弹窗操作,弹窗功能非常有用,不仅可以用于正式的app功能中,也可以在调试中使用.在OC中,UIAlertController类用来控制弹窗操作.在IOS 8.0之前, ...

  5. UI控件(UIAlertController)

    @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; UIButton *_button = [UIBut ...

  6. UIAlertController 部分用法及属性

    //创建UIAlertController:初始化UIAlertController 需要使用alertControllerWithTitle UIAlertController *alertCont ...

  7. iOS--UIAlertView与UIAlertController和UIAlertAction之间的事儿

      iOS 8的新特性之一就是让接口更有适应性.更灵活,因此许多视图控制器的实现方式发生了巨大的变化.全新的UIPresentationController在实现视图控制器间的过渡动画效果和自适应设备 ...

  8. 开始使用 UIAlertController 吧

    UIAlertView 与 UIActionSheet UIAlertView 样式 实现 - (void)showAlertView { self.alertView = [[UIAlertView ...

  9. UI第十四节——UIAlertController

    - (void)viewDidLoad {    [super viewDidLoad];        UIButton *alertBtn = [UIButton buttonWithType:U ...

  10. iOS 8.0后使用UIAlertController

    iOS 8的新特性之一就是让接口更有适应性.更灵活,因此许多视图控制器的实现方式发生了巨大的变化.全新的UIPresentationController在实现视图控制器间的过渡动画效果和自适应设备尺寸 ...

随机推荐

  1. HW4.40

    public class Solution { public static void main(String[] args) { long positiveSide = 0; long negativ ...

  2. HW3.29

    import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...

  3. POJ1811- Prime Test(Miller–Rabin+Pollard's rho)

    题目大意 给你一个非常大的整数,判断它是不是素数,如果不是则输出它的最小的因子 题解 看了一整天<初等数论及其应用>相关部分,终于把Miller–Rabin和Pollard's rho这两 ...

  4. oracle中exp,imp的使用详解

    http://www.cnblogs.com/yugen/archive/2010/07/25/1784763.html

  5. 有关gcc的扩展__attribute__((unused))

    ================================ Author: taoyuetao Email: tao_yuetao@yahoo.com.cn Blog: taoyuetao.cu ...

  6. [一]初识Poi

    示例代码: package com.lxl.poi; import java.io.FileOutputStream; import org.apache.poi.hssf.usermodel.HSS ...

  7. JS获取浏览器可视区域尺寸

    本文所说的是浏览器窗口的可视区域大小,不是浏览器窗口大小,也非页面尺寸. 在没有声明DOCTYPE的IE中,浏览器显示窗口大小只能以下获取: document.body.offsetWidth doc ...

  8. codis集群和redis cluster的优劣对比

    1.codis架构如下: (1)Codis是一整套缓存解决方案,包含高可用.数据分片.监控.动态扩态 etc..走的是 Apps->代理->redis cluster,一定规模后基本都采用 ...

  9. OcciWrapper使用指南(高性能Oracle访问组件)

    occiwrapper使用指南 occiwrapper是一个开源的.跨平台的Oracle访问组件, 方便C++开发者们灵活地操作oracle数据库.为了方便使用,组件中的接口形式参考的POCO库的使用 ...

  10. kali linux 之 DNS信息收集

    [dig]命令的使用: dig是linux中的域名解析工具,功能比nslookup强很多,使用也很方便. windows系统下使用dig须下载安装一下. 使用方法: root@kali:~# dig ...