UIAlertController

UIAlertController 是 IOS8以后才有的

UIAlertController 继承  UIViewController

UIAlertAction 继承 NSObject

可以给UIAlertController.view 属性 添加子视图


    /**  
     UIAlertController
     
     A UIAlertController object displays an alert message to the user. This class replaces the UIActionSheet and UIAlertView classes for displaying alerts. After configuring the alert controller with the actions and style you want, present it using the presentViewController:animated:completion: method
 
     UIAlertController 用来显示警告信息给用户,这个类代替 UIActionSheet 和UIAlertView
     配置完 actions 和  style 通过 presentViewController:animated:completion method
     
     */
    
    /** 
     
     UIAlertAction
     
     A UIAlertAction object represents an action that can be taken when tapping a button in an alert. You use this class to configure information about a single action, including the title to display in the button, any styling information, and a handler to execute when the user taps the button. After creating an alert action object, add it to a UIAlertController object before displaying the corresponding alert to the user.
     */
    

    /*
     UIAlertActionStyleCancel
     UIAlertActionStyleDefault
     UIAlertActionStyleDestructive
     
     配置时候不能配置相同的!
  
    UIAlertController: preferredStyle:
     
     UIAlertControllerStyleAlert
     UIAlertControllerStyleActionSheet
     */
    UIAlertController *alertController =  [UIAlertController alertControllerWithTitle:@"titile" message:@"message" preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction *cancel_AlertAction = [UIAlertAction actionWithTitle:@"Cancel_alertAction_title" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
        
        NSLog(@"Cancel_alertAction");
    }];
    
    UIAlertAction *default_AlertAction = [UIAlertAction actionWithTitle:@"Default_alertAction_title" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        
        NSLog(@"Default_alertAction");
        NSLog(@"%@",((UITextField*)alertController.textFields[0]).text);
    }];
    
    UIAlertAction *destructive_AlertAction = [UIAlertAction actionWithTitle:@"destructive_AlertAction" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
        NSLog(@"destructive_AlertAction");
    }];
    
    //给 AlertController 配置 aciton
    [alertController addAction:cancel_AlertAction];
    [alertController addAction:default_AlertAction];
    [alertController addAction:destructive_AlertAction];
    
    /**
     Calling this method adds an editable text field to the alert. You can call this method more than once to add additional text fields. The text fields are stacked in the resulting alert.
     */
    
    //配置输入框
    [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
        NSLog(@"SecureTextEntryTextFieldWithConfigurationHandler");
    }];
    
    [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
        NSLog(@"addTextFieldWithConfigurationHandler");
    }];
    
    //配置文本框的安全输入
    ((UITextField*)alertController.textFields[0]).secureTextEntry = YES;
     
    //弹出
     [self presentViewController:alertController animated:YES completion:^{
       
     }];

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值