美文网首页
IOS学习之 -- UIAlertController

IOS学习之 -- UIAlertController

作者: 就怕是个demo | 来源:发表于2015-11-20 16:36 被阅读119次

    AlertView 类型

    UIAlertController *controller = [UIAlertController alertControllerWithTitle:@"提示" message:@"登陆成功" preferredStyle:UIAlertControllerStyleAlert];
    //设置取消按钮
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];   
    //设置确定按钮  
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
        UITextField *username = controller.textFields.firstObject;
        NSLog(@"username = %@", username.text);
        UITextField *password = controller.textFields.lastObject;
        NSLog(@"password = %@", password.text);
    }];
    /*//添加输入框
    [controller addTextFieldWithConfigurationHandler:^(UITextField *textField){
        textField.placeholder = @"用户名";
    }];
    [controller addTextFieldWithConfigurationHandler:^(UITextField *passwrod){
        passwrod.placeholder = @"密码";
        passwrod.secureTextEntry = YES;
    }];*/
    [controller addAction:cancelAction];
    [controller addAction:okAction];
    [self presentViewController:controller animated:YES completion:nil];
    

    ActionSheet 类型

    UIAlertController *controller = [UIAlertController alertControllerWithTitle:@"请选择" message:@"股市有风险" preferredStyle:UIAlertControllerStyleActionSheet];
    UIAlertAction *save = [UIAlertAction actionWithTitle:@"保存" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
        NSLog(@"title = %@", action.title);
    }];
    UIAlertAction *delet = [UIAlertAction actionWithTitle:@"删除" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
        NSLog(@"title = %@", action.title);
    }];
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action){
        NSLog(@"title = %@", action.title);
    }];
    [controller addAction:save];
    [controller addAction:delet];
    [controller addAction:cancel];
    [self presentViewController:controller animated:YES completion:nil];

    相关文章

      网友评论

          本文标题:IOS学习之 -- UIAlertController

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