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

iOS9 UIAlertController简单使用代码

2016-02-29 11:14 417 查看
iOS9 xcode7以后,很多方法都过期了,被新的方法所代替。在这里我主要介绍两个常用的控件——UIAlertView、UIActionSheet被替代的新控件——UIAlertController的使用。

一、UIAlertController的UIActionSheet效果时的用法

UIAlertController * sheet = [UIAlertControlleralertControllerWithTitle:nilmessage:@"选择性别"preferredStyle:UIAlertControllerStyleActionSheet];

[sheetaddAction:[UIAlertActionactionWithTitle:@"男"style:UIAlertActionStyleDefaulthandler:^(UIAlertAction
*_Nonnull action) {

NSLog(@"在这里处理选择之后的事");

}]];

[sheet addAction:[UIAlertActionactionWithTitle:@"女"style:UIAlertActionStyleDefaulthandler:^(UIAlertAction
*_Nonnull action) {

NSLog(@"在这里处理选择之后的事");

}]];

[sheetaddAction:[UIAlertActionactionWithTitle:@"取消"style:UIAlertActionStyleCancelhandler:nil]];

[selfpresentViewController:sheetanimated:YEScompletion:nil];

二、UIAlertController的UIAlertView效果时的用法

UIAlertController * alert = [UIAlertControlleralertControllerWithTitle:@"提示"message:@"请输入手机号"preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction *okAction = [UIAlertActionactionWithTitle:@"确定"style:(UIAlertActionStyleCancelhandler:^(UIAlertAction
*action) {

NSLog(@"在这里处理点击按钮之后的事");

}];

[alert addAction:okAction];

[selfpresentViewController:alert
animated:YEScompletion:nil];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: