ios8 下面的alert和actionsheet

来源:互联网 发布:七天网络阅卷系统2017 编辑:程序博客网 时间:2024/05/22 10:29

iOS8下面已经更换了alert和action sheet,可能出于某种考虑,其实空间的统一化,对开发者是件好事!

现在统一为

UIAlertController

无比记住,必须用sdk8编译才有这样的api,而且必须ios8以上才能使用,来看下

UIAlertController * alert = [UIAlertController alertControllerWithTitle:nil message:@"\n请输入参数" preferredStyle:UIAlertControllerStyleAlert];    [alert addAction:[UIAlertAction actionWithTitle:@"Delete"                                                                    style:UIAlertActionStyleDefault                                                                  handler:^(UIAlertAction *action) {                                                                                                NSLog(@"111");                                                                                            }]];        [alert addAction:[UIAlertAction actionWithTitle:@"Cancel"                                                                    style:UIAlertActionStyleCancel                                                                  handler:^(UIAlertAction *action) {                                                                                                NSLog(@"222");                                                                                            }]];    [self presentViewController:alert animated:YES completion:nil];

这个是创建alert,那么怎么创建action sheet呢

typedef NS_ENUM(NSInteger, UIAlertControllerStyle) {    UIAlertControllerStyleActionSheet = 0,    UIAlertControllerStyleAlert} NS_ENUM_AVAILABLE_IOS(8_0);

两个枚举类型,分别就是sheet和alert,看看枚举就知道了。在初始化的时候,传入不同的类型就ok

初始化函数

alertControllerWithTitle:(NSString *)title message:(NSString *)message preferredStyle:(UIAlertControllerStyle)preferredStyle

其实使用起来十分方便,首先加入的action就3种,我在此列举下:

typedef NS_ENUM(NSInteger, UIAlertActionStyle) {    UIAlertActionStyleDefault = 0,    UIAlertActionStyleCancel,    UIAlertActionStyleDestructive} NS_ENUM_AVAILABLE_IOS(8_0);

defult和cancel不用说了,另外一个是action sheet的时候使用的加亮按钮操作,如今他把每个操作,都用一个block传入函数,可以看出block的重要性越来越大,其实工程我们也需要经常使用起来。

还是和以前一样,alert还是只支持textfield,这个特性很让人纠结,希望后期还是开放一个更大的权限给我们,不至于我们写第三方空间,加textfiled和action差不多

- (void)addTextFieldWithConfigurationHandler:(void (^)(UITextField *textField))configurationHandler

好了,大家快去试试吧,很给力哦!


0 0
原创粉丝点击