楼主在整理项目的警告,于是乎你懂的。

然后自己整理了一下以后方便自己忘了之后能及时找到它

关于UIAlertController .h文件的解析

/**
关于UIAlertController的解析
*/ #import <UIKit/UIViewController.h>
//
NS_ASSUME_NONNULL_BEGIN //枚举 UIAlertActionStyle
typedef NS_ENUM(NSInteger, UIAlertActionStyle) {
UIAlertActionStyleDefault = ,//默认
UIAlertActionStyleCancel,//取消
UIAlertActionStyleDestructive//颜色突出的
} NS_ENUM_AVAILABLE_IOS(8_0);
//枚举 UIAlertControllerStyle
typedef NS_ENUM(NSInteger, UIAlertControllerStyle) {
UIAlertControllerStyleActionSheet = ,//actionSheet// 从底部弹出
UIAlertControllerStyleAlert//alertView 从中间弹出
} NS_ENUM_AVAILABLE_IOS(8_0); /* ********************************UIAlertAction********************************/
//aletviewCon的内部模块按钮
NS_CLASS_AVAILABLE_IOS(8_0) @interface UIAlertAction : NSObject <NSCopying>
/**
* 类方法创建
*
* @param title 标题内容
* @param style action的样式
* @param handler 点击后执行的操作block模式
*
* @return
*/
+ (instancetype)actionWithTitle:(nullable NSString *)title style:(UIAlertActionStyle)style handler:(void (^ __nullable)(UIAlertAction *action))handler;
@property (nullable, nonatomic, readonly) NSString *title;
@property (nonatomic, readonly) UIAlertActionStyle style;
//是否可点击
@property (nonatomic, getter=isEnabled) BOOL enabled; @end /* ********************************UIAlertController********************************/ NS_CLASS_AVAILABLE_IOS(8_0) @interface UIAlertController : UIViewController
/**
* 工厂方法创建
*
* @param title 标题
* @param message 详细标题
* @param preferredStyle 样式
*
* @return
*/
+ (instancetype)alertControllerWithTitle:(nullable NSString *)title message:(nullable NSString *)message preferredStyle:(UIAlertControllerStyle)preferredStyle;
/**
* 添加按钮
*
* @param action
*/
- (void)addAction:(UIAlertAction *)action;
//按钮数组()只读的
@property (nonatomic, readonly) NSArray<UIAlertAction *> *actions;
//偏好action,将以后的action设置为偏好action,action的字体会加粗
@property (nonatomic, strong, nullable) UIAlertAction *preferredAction NS_AVAILABLE_IOS(9_0);
//alerviewstyle添加文本框的方法 可在block设置textfield的属性
- (void)addTextFieldWithConfigurationHandler:(void (^ __nullable)(UITextField *textField))configurationHandler;
@property (nullable, nonatomic, readonly) NSArray<UITextField *> *textFields;//装有往弹窗添加的文本框的数组(只读) @property (nullable, nonatomic, copy) NSString *title;
@property (nullable, nonatomic, copy) NSString *message;
@property (nonatomic, readonly) UIAlertControllerStyle preferredStyle;//样式(只读) @end NS_ASSUME_NONNULL_END

使用代码

在button点击事件中

- (IBAction)button:(id)sender {
// UIAlertController *alertCon = [UIAlertController alertControllerWithTitle:@"提示" message:@"wocao" preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertController *alertCon = [UIAlertController alertControllerWithTitle:@"提示" message:@"wocao" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"默认" style:UIAlertActionStyleDefault handler:nil];
UIAlertAction *action3 = [UIAlertAction actionWithTitle:@"不知道" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"wocaodelai ");
}];
// action3.enabled = NO;
[alertCon addAction:action1];
[alertCon addAction:action2];
[alertCon addAction:action3];
alertCon.preferredAction = action3;
[alertCon addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.textColor = [UIColor redColor];
}];
[alertCon addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.textColor = [UIColor yellowColor];
textField.textAlignment = NSTextAlignmentRight;
}];
// NSLog(@"textFields %@", alertCon.textFields);
[self presentViewController:alertCon animated:YES completion:nil];
}

UIAlertController的更多相关文章

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

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

  2. UIAlertController使用

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

  3. IOS UIAlertController 使用方法

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

  4. UI控件(UIAlertController)

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

  5. UIAlertController 部分用法及属性

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

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

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

  7. 开始使用 UIAlertController 吧

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

  8. UI第十四节——UIAlertController

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

  9. iOS 8.0后使用UIAlertController

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

随机推荐

  1. Java程序设计之Constructor

    插入段代码,下次回忆吧. 先新建一个Person类,代码如下: public class Person { private String name ; private int age; public ...

  2. 第10章 Shell编程(2)_字符截取命令

    2. 字符截取命令 2.1 cut字段提取命令(grep提取行,cut提取列) (1)cut命令:#cut [选项] 文件名 选项: -f 列号:提取第几列: -d 分隔符:按照指定分隔符分割列,默认 ...

  3. [No00008F]PLSQL自动登录,记住用户名密码&日常使用技巧

    配置启动时的登录用户名和密码 这是个有争议的功能,因为记住密码会给带来数据安全的问题. 但假如是开发用的库,密码甚至可以和用户名相同,每次输入密码实在没什么意义,可以考虑让PLSQL Develope ...

  4. PHP基础语法

             PHP:超级文本预处理器一,PHP的四对标记 <?php ?> <script language="php"> <script> ...

  5. [LeetCode] Wiggle Sort II 摆动排序

    Given an unsorted array nums, reorder it such that nums[0] < nums[1] > nums[2] < nums[3]... ...

  6. HFSS仿真小例

    微带拐角对比实验 微带四分之波长变换器插入前后对比 P1 P2 分配波端口激励,设置差分信号线 微带线差分对的差模阻抗随着差分线间距的增大而增大,随着线宽的增大而减小: 共模阻抗随着差分线间距的增大而 ...

  7. 【C#】类单例 可以解决全局变量的问题

    单件模式(Singleton):保证一个类仅有一个实例,并提供一个访问它的全局访问点. 知道 详解

  8. 记录rewrite url我之前不知道的地方

    大部分url重写的需求是伪静态,当然有很多第三方开源组件,但是这种需求的核心方法其实就是context.rewritePath() 要是系统像ARR那样,用重写做代理和反向代理,一般的重写就不行了,c ...

  9. spriing boot 实战

    一.spring基础 1. 依赖注入 我们常说的控制翻转(Inversion of Control -IOC)和依赖注入(dependency injection-DI)在Spring环境下是等同的概 ...

  10. 封装一个函数获取匹配特定的css选择符

    function $$(selector,context){ context=context||document; var elements=context.querySelectorAll(sele ...