美文网首页
UIAlercontroller 警告框

UIAlercontroller 警告框

作者: 墨凌风起 | 来源:发表于2016-07-15 16:10 被阅读158次

    //alert  标题  提示信息  警告框的形式

    ```

    UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"警告" message:@"提示信息" preferredStyle:UIAlertControllerStyleAlert];

    //增加选项1

    [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

    //点击确认按钮的事件

    NSLog(@"确定键被触发----");

    }]];

    //增加选项2

    [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {

    //        点击取消按钮的事件的

    NSLog(@"取消按钮被触发-----");

    }]];

    //增加输入框

    [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {

    //可以进行文本框订制信息  后续操作

    textField.backgroundColor = [UIColor redColor];

    }];

    //展现方式

    [self presentViewController:alert animated:YES completion:nil];

    //延时2秒后自动消失

    [self performSelector:@selector(dismissAlert:) withObject:alert afterDelay:2];

    -(void)dismissAlert:(UIAlertController *)alert{

    if (alert) {

    [alert dismissViewControllerAnimated:YES completion:nil];

    }

    }

    ```

    /************************页面底部弹框************************

    ```

    UIAlertController * actionSheet = [UIAlertController alertControllerWithTitle:@"分享" message:@"提示" preferredStyle:UIAlertControllerStyleActionSheet];

    [actionSheet addAction:[UIAlertAction actionWithTitle:@"新浪微博" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

    NSLog(@"分享到新浪微博  ---- ");

    }]];

    [actionSheet addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];

    [self presentViewController:actionSheet animated:YES completion:nil];

    ```

    相关文章

      网友评论

          本文标题:UIAlercontroller 警告框

          本文链接:https://www.haomeiwen.com/subject/tneljttx.html