OC的UI开发基础之警告提示框——UIAlertController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    /**
     UIAlertController必须经过触发才会出现,因此设置在点击屏幕的方法中演示,不再设置在viewDidLoad中
     */
    
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"我是标题" message:@"我是提示文字" preferredStyle:UIAlertControllerStyleAlert];
    /**
     UIAlertControllerStyleActionSheet = 0,//从底部出现的抽屉风格
     UIAlertControllerStyleAlert//弹窗d风格
     除文本框之外,基本使用方法相同
     */
    
    /**
     如果是两个一下的按钮,则会出现在一行。两个以上则会是垂直分布。
     */
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    /**style的枚举如下
     UIAlertActionStyleDefault = 0, 默认
     UIAlertActionStyleCancel,       取消风格(如果是两个按钮,则取消风格的按钮一直在最左边,如果是三个按钮则会出现最下边)
     UIAlertActionStyleDestructive 红色风格
     */
    
    /**handler
     设置点击事件
     */
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:nil];
    
    //设置一个高亮的按钮
    alert.preferredAction = alert.actions.firstObject;
    //添加一个文本输入框
    /**注意!!!
     UIAlertControllerStyleActionSheet不能添加文本框
     */
    [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
        textField.text = @"默认文字";
        textField.textColor = [UIColor orangeColor];
    }];
    [alert addAction:cancelAction];
    [alert addAction:okAction];
    [self presentViewController:alert animated:YES completion:nil];

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值