NS_CLASS_AVAILABLE_IOS(8_0) @interface UIAlertAction : NSObject <NSCopying>

//创建操作
+ (instancetype)actionWithTitle:(nullable NSString *)title style:(UIAlertActionStyle)style handler:(void (^ __nullable)(UIAlertAction *action))handler; NS_CLASS_AVAILABLE_IOS(8_0) @interface UIAlertController : UIViewController //初始化
+ (instancetype)alertControllerWithTitle:(nullable NSString *)title message:(nullable NSString *)message preferredStyle:(UIAlertControllerStyle)preferredStyle; //添加操作
- (void)addAction:(UIAlertAction *)action; 示例1:最简单的提醒视图 //创建操作
UIAlertAction *okAlert = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
//具体操作内容
}];
//初始化
UIAlertController *alert = [UIAlertControlleralertControllerWithTitle:@"顶部标题栏"message:@"中间信息"preferredStyle:UIAlertControllerStyleAlert];
//添加操作
[alert addAction:okAlert];
//以model形式,显示警告视图
[self presentViewController:alert animated:YES completion:nil]; // 等同于
NSString *title = @"顶部标题栏";
NSString *message = @"中间信息";
NSString *okAlertButton = @"OK";
UIAlertAction *okAlert = [UIAlertAction
actionWithTitle:okAlertButton style:UIAlertActionStyleDefaulthandler:^(UIAlertAction * _Nonnull action) { }]; UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert]; 示例2:多个按键的提醒视图 //取消按键——下次下次 UIAlertActionStyleCancel (粗体)
[alert addAction:[UIAlertAction actionWithTitle:@"下次下次" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"点击取消按钮");
}]]; //红色按键——残忍拒绝 UIAlertActionStyleDestructive
[alert addAction:[UIAlertAction actionWithTitle:@"残忍拒绝" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"红色按钮");
}]]; // 两个会是这样 // 3个就挨个往下排
//普通按键——立马好评 UIAlertActionStyleDefault [alert addAction:[UIAlertAction actionWithTitle:@"立马好评" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"普通按钮");
}]]; 示例3:带对话框TextField - (void)addTextFieldWithConfigurationHandler:(void (^ __nullable)(UITextField *textField))configurationHandler; //添加TextField 条栏 addTextFieldWithConfigurationHandler
[alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
NSLog(@"TextField");
//中间的提示输入
textField.placeholder = @"用来提示你做什么事的";
}]; 示例4:提醒图标,在最底部呈现 Sheet // UIAlertControllerStyleAlert改成UIAlertControllerStyleActionSheet (最后面的)
UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleActionSheet]; UIAlertControllerStyleActionsheet好像不能和TextField在一起,会报错。是这样吗? 疑问:排列没有次序?
用英文@“ok” 之类的,就会排列和我写的顺序一样。
NS_CLASS_AVAILABLE_IOS(8_0) @interface UIAlertAction : NSObject <NSCopying>
 
//创建操作
+ (

instancetype)actionWithTitle:(nullable NSString *)title style:(UIAlertActionStyle)style handler:(void (^ __nullable)(UIAlertAction *action))handler;

 
NS_CLASS_AVAILABLE_IOS(8_0) @interface UIAlertController : UIViewController
 
//初始化
+ (instancetype)alertControllerWithTitle:(nullable NSString *)title message:(nullable NSString *)message preferredStyle:(UIAlertControllerStyle)preferredStyle;
 
//添加操作
- (void)addAction:(UIAlertAction *)action;
 
 
示例1:最简单的提醒视图
 
//创建操作
    UIAlertAction *okAlert = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
     //具体操作内容
}];
//初始化
    UIAlertController *alert = [UIAlertControlleralertControllerWithTitle:@"顶部标题栏"message:@"中间信息"preferredStyle:UIAlertControllerStyleAlert];
//添加操作
    [alert addAction:okAlert];
//以model形式,显示警告视图
    [self presentViewController:alert animated:YES completion:nil];
 
 
// 等同于
    NSString *title = @"顶部标题栏";
    NSString *message = @"中间信息";
    NSString *okAlertButton = @"OK";
    UIAlertAction *okAlert = [UIAlertAction
actionWithTitle:okAlertButton style:UIAlertActionStyleDefaulthandler:^(UIAlertAction * _Nonnull action) {
       
    }];
 
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
 
 
示例2:多个按键的提醒视图
 
    //取消按键——下次下次 UIAlertActionStyleCancel   (粗体)
    [alert addAction:[UIAlertAction actionWithTitle:@"下次下次" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        NSLog(@"点击取消按钮");
    }]];
 
      //红色按键——残忍拒绝 UIAlertActionStyleDestructive  
    [alert addAction:[UIAlertAction actionWithTitle:@"残忍拒绝" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        NSLog(@"红色按钮");
    }]];
 
// 两个会是这样
 
 
// 3个就挨个往下排 
    //普通按键——立马好评 UIAlertActionStyleDefault  
    [alert addAction:[UIAlertAction actionWithTitle:@"立马好评" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        NSLog(@"普通按钮");
    }]];
 
 
 
示例3:带对话框TextField
 
- (void)addTextFieldWithConfigurationHandler:(void (^ __nullable)(UITextField *textField))configurationHandler;
 
     //添加TextField 条栏  addTextFieldWithConfigurationHandler 
    [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
        NSLog(@"TextField");
        //中间的提示输入
        textField.placeholder = @"用来提示你做什么事的";
    }];
 
 
示例4:提醒图标,在最底部呈现 Sheet
 
// UIAlertControllerStyleAlert改成UIAlertControllerStyleActionSheet (最后面的)
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleActionSheet];
 
 
UIAlertControllerStyleActionsheet好像不能和TextField在一起,会报错。是这样吗?
 
疑问:排列没有次序?
用英文@“ok” 之类的,就会排列和我写的顺序一样。
 
 

UIAlertController、UIAlertAction 警告框的更多相关文章

  1. IOS开发中UIAlertController(警告框)的使用

    步骤一.初始化: UIAlertController * inputname = [UIAlertController alertControllerWithTitle:@"未输入账户&qu ...

  2. iOS 学习笔记 九 (2015.04.02)IOS8中使用UIAlertController创建警告窗口

    1.IOS8中使用UIAlertController创建警告窗口 #pragma mark - 只能在IOS8中使用的,警告窗口- (void)showOkayCancelAlert{    NSSt ...

  3. iOS:提示框(警告框)控件UIActionSheet的详解

    提示框(警告框)控件2:UIActionSheet 功能:当点击按钮或标签等时,弹出一个提示框,显示必要的提示,然后通过添加的按钮完成需要的功能.它与导航栏类似,它继承自UIView.   风格类型: ...

  4. SweetAlert-js超酷消息警告框插件

    简要教程 SweetAlert是一款神奇的javascript弹出消息警告框插件. 来通过一张gif图片看看SweetAlert的效果: 使用方法 要使用该插件,首先要在html的header中引入以 ...

  5. selenium+webdriver+python 中警告框的处理方法

    在自动化测试过程中,经常会遇到弹出警告框的情况,如图所示: 在 WebDriver 中处理 JavaScript 所生成的 alert.confirm 以及 prompt 是很简单的.具体做法是使用  ...

  6. Bootstrap 弹出框和警告框插件

    一.弹出框 弹出框即点击一个元素弹出一个包含标题和内容的容器. //基本用法 <button class="btn btn-lg btn-danger" type=" ...

  7. bootstrap-巨幕、缩略图、警告框

    巨幕: <div class="jumbotron"> <div class="container"> <h1>W3Scho ...

  8. Bootstrap 巨幕页头缩略图和警告框组件

    一.巨幕组件 //在固定的范围内,有圆角 <div class="container"> <div class="jumbotron"> ...

  9. ios9 之后,Xcode7不推荐使用UIAlertView,改用UIAlertController+UIAlertAction(按钮)

    /** *  ios9 之后,Xcode7不推荐使用UIAlertView,改用UIAlertController+UIAlertAction(按钮) */ UIAlertController *al ...

随机推荐

  1. 简单的androidStudio 添加Jar包

    感谢http://blog.csdn.net/ta893115871/article/details/46955791博主的文章, 1新建一个空项目 2在项目下添加一个新的moudle 3在该moud ...

  2. Logstash 父子关系 配置

    最近在使用Lostash的过程中遇到了一个问题:在一个log文件里包含两类数据,而且两类数据之间存在父子关系,那如何使用lostash的configuration实现这个需求呢 思路: 首先定义父事件 ...

  3. 简单的block

    int multi = 7;                int (^myBlock)(int) = ^(int num){            return num * multi;       ...

  4. WPF触发器的使用

    WPF中定义了五个触发器类:Trigger.MultiTrigger.DataTrigger.multiDataTrigger.EventTrigger.下面我来介绍一下怎么使用这几个触发器的使用方法 ...

  5. 十.oc内存管理

    引用百度百科图 栈(stack)又名堆栈. 栈定义:栈是限定仅在表头进行插入和删除操作的线性表(有序).(又称:后进先出表) (动态)数据展示存储的地方.(举例:升降电梯)特点:先进后出(FILO—F ...

  6. otter双主同步安装与配置

    otter是阿里的开源数据同步项目,资源地址就不用说了哈,网上找,阿里云论坛关于单方向同步的配置已经很清楚了,理论上说,双主同步也不复杂,但是毕竟 是数据库,比较重要,配置双主的时候,总觉得心里没底, ...

  7. VLC嵌入网页,终于要成功了!

    <OBJECT classid="clsid:9BE31822-FDAD-461B-AD51-BE1D1C159921" width="640" heig ...

  8. JavaScript 详说事件机制之冒泡、捕获、传播、委托

    DOM事件流(event  flow )存在三个阶段:事件捕获阶段.处于目标阶段.事件冒泡阶段. 事件捕获(event  capturing):通俗的理解就是,当鼠标点击或者触发dom事件时,浏览器会 ...

  9. 说一说line-height

    line-height这个样式相信大家一定不会陌生,我们经常用它来让文本上下居中,这样做一般不出出现什么问题,但是如果对这个属性不是很熟悉的话,可能会踩到一些坑,今天亲自去试验了一下,并总结了一下li ...

  10. 粗略读完opengl

    清明节前粗略读完了opengl编程指南第七版,对opengl有了一个大体的了解,并且了解的也很肤浅.有了计算机图形学,线性代数的基础,读起来也不像以前那么吃力了.从简单的绘制点,直线,多边形,到视图变 ...