IOS UIAlertControl与UIAlertAction

在ios8中UIAlertAction以及UIAlertControl替代了原来的UIAlertSheet以及UIAlertView,值得注意的是UIAlertControl继承的事UIViewControl!


/*
typedef NS_ENUM(NSInteger, UIAlertControllerStyle) {
    UIAlertControllerStyleActionSheet = 0,
    UIAlertControllerStyleAlert
} NS_ENUM_AVAILABLE_IOS(8_0);
*/
//在这里我们可以决定我们要用的是原来的AlertView还是AlertSheet
//也就是说他们由两个控件变成了一个控件的两个Style
alertcontrol = [UIAlertController 
alertControllerWithTitle:@"title" message:@"message" preferredStyle:UIAlertControllerStyleAlert];


    [alertcontrol addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
        textField.placeholder = @"方便了很多";

/*
typedef NS_ENUM(NSInteger, UIAlertActionStyle) {
    UIAlertActionStyleDefault = 0,//默认的风格
    UIAlertActionStyleCancel,//取消按钮的风格
    UIAlertActionStyleDestructive//警告的风格
}
*/
    UIAlertAction * alert = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {

    }];

    UIAlertAction * alert2 = [UIAlertAction actionWithTitle:@"取消2" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {

    }];



    [alertcontrol addAction:alert];
    [alertcontrol addAction:alert2];

因为继承的是UIViewControl所以我们需要使用模态present,将UIViewControl Present出来,并且我们不能直接在Viewdid里面进行编写 在这里我们点击空白进行present

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

    [self presentViewController:alertcontrol animated:YES completion:^{

    }];

}

在这里我们可以加入多个UITextField而不是以前最多两个

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值