UIAlertController的用法

    xiaoxiao2021-03-26  34

    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];

    转载请注明原文地址: https://ju.6miu.com/read-664254.html

    最新回复(0)