您的位置:首页 > 产品设计 > UI/UE

IOS UIAlertControl与UIAlertAction

2016-01-07 14:02 387 查看
在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而不是以前最多两个
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: