iOS UIAlertController提示框

这里写图片描述

UIAlertController实现如图效果

我设置了一个按钮,在按钮的点击事件里写的以下代码:

- (void)action:(UIButton *)btn{
    //创建提示框
    UIAlertController *ac = [UIAlertController alertControllerWithTitle:@"这里" message:@"成功" preferredStyle:UIAlertControllerStyleAlert];
    //创建提示框取消按钮
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
        NSLog(@"点击的是取消");
    }];
    //创建提示框OK按钮
    UIAlertAction *ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
    }];
    //把按钮加在提示框上
    [ac addAction:cancel];
    [ac addAction:ok];
//弹出提示框
    [self presentViewController:ac animated:YES completion:^{

    }];

}

提示框上也可以加入UITextField,效果如图:
这里写图片描述

代码如下:

- (void)action:(UIButton *)btn{
    //创建提示框
    UIAlertController *ac = [UIAlertController alertControllerWithTitle:@"这里" message:@"成功" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
        NSLog(@"点击的是取消");
    }];
    UIAlertAction *ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        //在提示框上创建UITextField
        UITextField *username = ac.textFields[0];
        UITextField *password = ac.textFields[1];
        NSLog(@"username = %@", username);
        NSLog(@"password = %@", password);
    }];
    //将提示框按钮添加到提示框上
    [ac addAction:cancel];
    [ac addAction:ok];
    //在UITextField上添加暗字
    [ac addTextFieldWithConfigurationHandler:^(UITextField *textField) {
        textField.placeholder = @"用户名";
    }];
    [ac addTextFieldWithConfigurationHandler:^(UITextField *textField) {
        textField.placeholder = @"密码";
    }];
    //弹出提示框
    [self presentViewController:ac animated:YES completion:^{

    }];
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值