UIAlertController的用法

来源:互联网 发布:网络电视剧收视率 编辑:程序博客网 时间:2024/05/18 22:46

ios8不用于以前,uiAlertController属于UIViewController,而以前UIAlertView是属于UIView的。 

//添加对话提示框

        UIAlertController *actionSheetController = [UIAlertController alertControllerWithTitle:@"提示" message:@"请选择”"preferredStyle:UIAlertControllerStyleAlert];

        UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:@"确定"style:UIAlertActionStyleDestructivehandler:^(UIAlertAction * action) {}];

        [actionSheetController addAction:actionCancel];

        [actionSheetController.view setTintColor:[UIColor redColor]];

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


用法二---多选项

UIAlertController *actionSheetController = [UIAlertController alertControllerWithTitle:@"action选项" message:nilpreferredStyle:UIAlertControllerStyleActionSheet];

        UIAlertAction *action0 = [UIAlertAction actionWithTitle:@"选项一" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {

            [self customMethod1];

                                                        }];

        [actionSheetController addAction:action0];

        

        UIAlertAction *action = [UIAlertAction actionWithTitle:@"选项二" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {

        [self <span style="font-family: Arial, Helvetica, sans-serif;">customMethod2</span>];

                                                       }];

        UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"选项三" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {

            

            [self customMethod3];

                                                        }];

        UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) {}];

        

        [actionSheetController addAction:action];

        [actionSheetController addAction:action1];

        [actionSheetController addAction:actionCancel];

        [actionSheetController.view setTintColor:[UIColor greenColor]];

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


0 0
原创粉丝点击