iOS9提示框UIAlertController

2015-10-29  本文已影响2193人  Nedoloroso

iOS8之前

iOS8开始及iOS9之后

 UIAlertController *alert = [UIAlertController alertControllerWithTitle:<#(nullable NSString *)#> message:<#(nullable NSString *)#> preferredStyle:<#(UIAlertControllerStyle)#>]
* Title和message是看自己的需求传值,要实现上图中的效果只需要传nil即可,preferredStyle是设置提示框的类型,有两种可以选择
    // 底部提示框
    UIAlertControllerStyleActionSheet
    // 中部提示框
    UIAlertControllerStyleAlert
    [alert addAction:[UIAlertAction actionWithTitle:@"收藏" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
    }]];
    [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
    }]];
* 这里的style也有三个可以选择,根据自己需求选择即可
    UIAlertActionStyleDefault,  //默认
    UIAlertActionStyleCancel,  //取消
    UIAlertActionStyleDestructive  //警告
    [self.window.rootViewController presentViewController:alert animated:YES completion:nil];
上一篇 下一篇

猜你喜欢

热点阅读