UIAlertController的使用方…

取消了UIAlertView代替的是UIAlertController。


//        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"注册" message:@"注册之前请先充钱" preferredStyle:(UIAlertControllerStyleActionSheet)];区别是,个个是出现在最下面,并且当中有空格

//        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"注册" message:@"注册之前请先充钱" preferredStyle:(UIAlertControllerStyleAlert)];//这个事连接的

        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"注册" message:@"注册之前请先充钱" preferredStyle:(UIAlertControllerStyleAlert)];

        //这个则是出现在中间,并且中间只有一丝横线做为空隙,这个是出现提示的方式及要显示的字,title则是主题,另一个则是主题之后的message,就是提示信息

        [alert addAction:[UIAlertAction actionWithTitle:@"充值" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {

            NSLog(@"充值成功");//这个就是点击之后会跳到原页面,要想点击之后还在原界面,得添加,和默认的区别就在于字体的颜色和深度上

            [self dismissViewControllerAnimated:YES completion:^{

                NSLog(@"充值成功可以注册");

            }];

        }]];

       

  

        [alert addAction:[UIAlertAction actionWithTitle:@"我再考虑考虑" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

            NSLog(@"考虑毛线");//这个就是点击之后会跳到原页面

            [self presentViewController:alert animated:YES completion:NULL];

        }]];

        [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {

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

        

        

        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleTextFieldTextDidChangeNotification:) name:UITextFieldTextDidChangeNotification object:textField];

        

        textField.secureTextEntry = YES;

        

        textField.backgroundColor = [UIColor whiteColor];

        //这是在alert里面添加输入时加入的,用通知结束的时候记得移除通知

        

    }];  

       [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {

            exit(0);//这个是红色字因为退出什么的警告需要用到

             [[NSNotificationCenter defaultCenter] removeObserver:self name:UITextFieldTextDidChangeNotification object:alert.textFields.firstObject];//移除

        }]];

        [self presentViewController:alert animated:YES completion:NULL];

    [self dismissViewControllerAnimated:YES completion:NULL];//是否取消,后面的是消失前发送什么

//    self.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;//这个动画效果是反转

        self.modalTransitionStyle = 0;//默认下拉

        //UIModalTransitionStyleCrossDissolve;//直接一闪




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值