iOS8的UIAlertController
2016-06-29 00:00
429 查看
好吧 我很懒, 我看这太简单了, 直接贴api了. 作为一个iOSer, 这东西两分钟都看完了, 对不?
![](http://i4.piimg.com/567571/16f58279a44a4973.jpg)
1. UIAlertController类
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; @property (nonatomic, readonly) NSArray<UIAlertAction *> *actions; @property (nonatomic, strong, nullable) UIAlertAction *preferredAction NS_AVAILABLE_IOS(9_0); - (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
2. UIAlertAction类以及结构体
typedef NS_ENUM(NSInteger, UIAlertActionStyle) { UIAlertActionStyleDefault = 0, UIAlertActionStyleCancel, UIAlertActionStyleDestructive } NS_ENUM_AVAILABLE_IOS(8_0); typedef NS_ENUM(NSInteger, UIAlertControllerStyle) { UIAlertControllerStyleActionSheet = 0, UIAlertControllerStyleAlert } NS_ENUM_AVAILABLE_IOS(8_0); NS_CLASS_AVAILABLE_IOS(8_0) @interface UIAlertAction : NSObject <NSCopying> + (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
3. 注意点
测试发现, 当有一个UIAlertAction是取消类型时候, 不管这个action是第几个被添加进去的, 都会被放在最底部,如图:
![](http://i4.piimg.com/567571/16f58279a44a4973.jpg)
- (void)tapGestureClick:(UITapGestureRecognizer *)tapGesture { NSLog(@"点了图片"); UIAlertController *alertSheet = [UIAlertController alertControllerWithTitle:@"提醒" message:@"请选择图片来源" preferredStyle:0]; UIAlertAction *takePicture = [UIAlertAction actionWithTitle:@"拍一张" style:0 handler:^(UIAlertAction * _Nonnull action) { NSLog(@"拍一张"); }]; UIAlertAction *photoAlbum = [UIAlertAction actionWithTitle:@"从相册中选择" style:0 handler:^(UIAlertAction * _Nonnull action) { NSLog(@"从相册中选择"); }]; UIAlertAction *cancleBtn = [UIAlertAction actionWithTitle:@"取消" style:1 handler:nil]; [alertSheet addAction:cancleBtn]; [alertSheet addAction:takePicture]; [alertSheet addAction:photoAlbum]; [self presentViewController:alertSheet animated:YES completion:nil]; }
相关文章推荐
- UITextField的leftView和rightView
- SoapUI+Groovy做接口自动化测试
- 更新BLE的设备后,OSX LightBlue 不会更新扫描到Service
- 多线程学习之--真的不能在子线程里更新UI吗?
- Saving Data --- Saving Key-Value Sets(一)
- 编辑器Ueditor找不到临时文件解决办法
- android事件分发(三)重要的函数requestDisallowInterceptTouchEvent
- 《UNIX环境高级编程(第三版)》中apue.h头文件的设置
- 禁止UITextField 使用粘贴复制功能
- (OK) How to access a NAT guest from host with VirtualBox - NAT Port Forwarding
- C#中Dictionary<TKey,TValue>排序方式
- Ring3下Hook NtQueryDirectoryFile隐藏文件
- TypeError: value is out of bounds
- LeetCode - 155. Min Stack
- QQ好友分组添加好友(UITableView实现)
- LeetCode - 232. Implement Queue using Stacks
- 优先级队列:PriorityQueue
- ACM--DP--HDOJ 1005--Number Sequence
- 抗锯齿方法paint.setAntiAlias(ture);paint.setFilterBitmap(true))
- Hibernate 之 初识 uuid 和 native