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. COM中需要调用AddRef和Release的10条规律

    COM中需要调用AddRef和Release的10条规律  

  2. 原生js操作dom备忘

    <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf-8& ...

  3. Parallel线程使用

    Parallel的静态For,ForEach和Invoke方法       在一些常见的编程情形中,使用任务也许会提升性能.为了简化编程,静态类System.Threading.Tasks.Paral ...

  4. java中String、stringbuilder、stringbuffer区别

    1.可变与不可变 String类中使用字符数组保存字符串,如下就是,因为有"final"修饰符,所以可以知道string对象是不可变的.每次对String对象进行改变的时候其实都等 ...

  5. VIM操作常用指令(转)

    vim是上Linux非常常用的编辑器,很多Linux发行版都默认安装了vi(vim).vi(vim)命令繁多但是如果使用灵活之后将会大大提高效率.vi是"visual interface&q ...

  6. jquery api

    1. clone()可以复制一个节点 2. .prop()方法为元素赋属性值非常方便. $("input").prop("disabled", false); ...

  7. Halcon学习之tuple

    * define a tuple for int, double, string... not for object d:=[] * assignment d[0] := 'a string' * g ...

  8. CC1310之使用SMARTRF STUDIO

    SMARTRF STUDIO是TI提供的射频测试软件,在调射频的时候非常非常非常好用,推荐每一个使用TI射频芯片的工程师都要掌握. 1 如何使用? 要使用SMARTRF STUDIO,硬件必须连接仿真 ...

  9. java_jdk_JDK版本切换批处理脚本

    我们平时在window上做开发的时候,可能需要同时开发两个甚至多个项目,有时不同的项目对JDK的版本要求有区别,这时候我们可能会在一台电脑上安装多个版本的JDK,如下图所示:

  10. 大话JSON之Gson解析JSON

    (三)解析Json数组(多条Json数据) 比如有如下Json数据: [{'name':'John', 'grade':[{'course':'English','score':100},{'cour ...