UIAlertController
楼主在整理项目的警告,于是乎你懂的。
然后自己整理了一下以后方便自己忘了之后能及时找到它
关于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的更多相关文章
- iOS UIAlertController跟AlertView用法一样 && otherButtonTitles:(nullable NSString *)otherButtonTitles, ... 写法
今天写弹出框UIAlertController,用alertView习惯了,所以封装了一下,跟alertView用法一样,不说了,直接上代码: 先来了解一下otherButtonTitles:(nul ...
- UIAlertController使用
// 将UIAlertController模态出来 相当于UIAlertView show 的方法// 初始化一个一个UIAlertController // 参数preferredStyle: ...
- IOS UIAlertController 使用方法
在很多种语言中,alert都表示弹窗操作,弹窗功能非常有用,不仅可以用于正式的app功能中,也可以在调试中使用.在OC中,UIAlertController类用来控制弹窗操作.在IOS 8.0之前, ...
- UI控件(UIAlertController)
@implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; UIButton *_button = [UIBut ...
- UIAlertController 部分用法及属性
//创建UIAlertController:初始化UIAlertController 需要使用alertControllerWithTitle UIAlertController *alertCont ...
- iOS--UIAlertView与UIAlertController和UIAlertAction之间的事儿
iOS 8的新特性之一就是让接口更有适应性.更灵活,因此许多视图控制器的实现方式发生了巨大的变化.全新的UIPresentationController在实现视图控制器间的过渡动画效果和自适应设备 ...
- 开始使用 UIAlertController 吧
UIAlertView 与 UIActionSheet UIAlertView 样式 实现 - (void)showAlertView { self.alertView = [[UIAlertView ...
- UI第十四节——UIAlertController
- (void)viewDidLoad { [super viewDidLoad]; UIButton *alertBtn = [UIButton buttonWithType:U ...
- iOS 8.0后使用UIAlertController
iOS 8的新特性之一就是让接口更有适应性.更灵活,因此许多视图控制器的实现方式发生了巨大的变化.全新的UIPresentationController在实现视图控制器间的过渡动画效果和自适应设备尺寸 ...
随机推荐
- [No000093]按住Alt 再按数字键敲出任意汉字和字符!
1.在notepad里,(中文系统下) 按住Alt 然后按52946最后放开Alt 按住Alt 然后按45230最后放开Alt 按住Alt 然后按50403最后放开Alt 你会看到"我爱你& ...
- 让div盒子相对父盒子垂直居中的几种方法
div相对于父盒子垂直居中的几种方法,之前在网上看到很多种方法,确实说的很对,也很具体,但是我感觉对于初学者来说,一目了然是最重要的,所以,我把很高深的技巧,和很复杂的css样式都剔除掉,旨在让更多人 ...
- 如何配置Linux系统的网络IP地址
一台安装了Linux系统的电脑如果想要联网,首先要做的就是进行网络配置.今天小编就以CentOS6.4系统为例为大家介绍整个网络配置的过程,虽然只是以CentOS6.4系统为例,但是其它的Linux系 ...
- [LeetCode] Minimum Unique Word Abbreviation 最短的独一无二的单词缩写
A string such as "word" contains the following abbreviations: ["word", "1or ...
- Euler-Maruyama discretization("欧拉-丸山"数值解法)
欧拉法的来源 在数学和计算机科学中,欧拉方法(Euler method)命名自它的发明者莱昂哈德·欧拉,是一种一阶数值方法,用以对给定初值的常微分方程(即初值问题)求解.它是一种解决常微分方程数值积分 ...
- C#工程引用自定义目录的DLL
在App.config里配置: <configuration> <runtime> <assemblyBinding xmlns="urn:schemas-mi ...
- Medial Queries的另一用法——实现IE hack
众所周知,有些时候为了实现IE下的某些效果与现代浏览器一致,我们不得不使用一些hack手段来实现目的.比如说使用"\0","\"和"\9"来 ...
- 阻止pc端浏览器缩放js代码
阻止pc端浏览器缩放js代码 众所周知:移动端页面禁止用户缩放界面只需加上<meta name="viewport" content="user-scalable= ...
- 使用PrintDocument进行打印
背景: 1.在winform中,需要直接调用打印机,进行打印处理 2.找了很多实现方法是web的处理,然后查了下度娘,发现可以使用自带类PrintDocument进行处理,所以就有了这篇文章 说明: ...
- Android ListView上拉获取下一页
关于ListView上拉刷新的需求很多,实现方式也多种多样. 一般是简单的通过一个page变量来控制当前请求的页数,然后上拉的时候就发送请求. 实现出来后,经过测试哥的折腾,发现有诸多细节没有处理好, ...