您的位置:首页 > 产品设计 > UI/UE

UIAlertView和UIAlertController那点事儿

2016-07-21 13:32 435 查看
二、最基本的警告框

1、第一种方法

        UIAlertView * alter = [[UIAlertView
alloc]initWithTitle:@"标题"
message:@"这个是UIAlertView的默认样式"
delegate:self
cancelButtonTitle:@"取消"
otherButtonTitles:@"好的",
nil];

        [alter show];

2、第二种方法

UIAlertController *alertController = [UIAlertController
alertControllerWithTitle:@"标题" message:@"这个是UIAlertView的默认样式"
preferredStyle: UIAlertControllerStyleAlert];

UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:

                                       UIAlertActionStyleCancel handler:nil];

        UIAlertAction *deleteAction = [UIAlertAction actionWithTitle:@"登录"style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action)
{

            NSLog(@"删除,....");

        }];     

        [alertController addAction:cancelAction];

        [alertController addAction:deleteAction];

       //记得跳转

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



二、带有输入框的弹出框

        UIAlertController *alertController = [UIAlertController
      alertControllerWithTitle:@"文本对话框"
message:@"登录和密码的对话框示例"
preferredStyle:UIAlertControllerStyleAlert];

        //UIAlertControllerStyleActionSheet

        [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {

            // 可以在这里对textfield进行定制,例如改变背景色

            textField.backgroundColor = [UIColor
orangeColor];

        }];

        [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {

            // 可以在这里对textfield进行定制,例如改变背景色

            textField.backgroundColor = [UIColor
orangeColor];

        }];

        UIAlertAction *cancelAction = [UIAlertAction
actionWithTitle:@"取消"
style:

                                       UIAlertActionStyleCancel
handler:nil];

        UIAlertAction *deleteAction = [UIAlertAction
actionWithTitle:@"登录"
style:UIAlertActionStyleDestructive
handler:^(UIAlertAction *action) {

            UITextField *login = alertController.textFields.firstObject;

            UITextField *password = alertController.textFields.lastObject;

            NSLog(@"帐号:%@",login.text);

            NSLog(@"密码:%@",password.text);

        }];     

        [alertController addAction:cancelAction];

        [alertController addAction:deleteAction];

       //记得跳转

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



三、带有多个按钮删除类型的弹出框

UIAlertController *alertController = [UIAlertController
alertControllerWithTitle:@"保存或删除数据"
message:@"删除数据将不可恢复"
preferredStyle: UIAlertControllerStyleActionSheet];

        //UIAlertControllerStyleActionSheet

        

        [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {

            // 可以在这里对textfield进行定制,例如改变背景色

            textField.backgroundColor = [UIColor
orangeColor];

            //NSLog(@"ddd:%@",textField);

        }];

        [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {

            // 可以在这里对textfield进行定制,例如改变背景色

            textField.backgroundColor = [UIColor
orangeColor];

        }];

        UIAlertAction *cancelAction = [UIAlertAction
actionWithTitle:@"取消"
style:

                                       UIAlertActionStyleCancel
handler:nil];

        UIAlertAction *deleteAction = [UIAlertAction
actionWithTitle:@"删除"
style:UIAlertActionStyleDestructive
handler:^(UIAlertAction *action) {

            NSLog(@"quxiao,....");

//            UITextField *login = alertController.textFields.firstObject;

//            UITextField *password = alertController.textFields.lastObject;

//            NSLog(@"帐号:%@",login.text);

//            NSLog(@"密码:%@",password.text);

        }];

        UIAlertAction *archiveAction = [UIAlertAction
actionWithTitle:@"保存"
style:UIAlertActionStyleDefault
handler:nil];

//

        [alertController addAction:cancelAction];

        [alertController addAction:deleteAction];

        [alertController addAction:archiveAction];

        

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

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: