iOS UIAlertController弹窗效果
2016-07-25 15:30
489 查看
在iOS8之前弹窗一共有两种方式分为UIAlertView和UIActionSheet,在iOS8之后新增UIAlertViewController来统一管理,下面就来一一作介绍
1.UIAlertView
// message 可设置为nil,cancelButtonTitle也可设置为nil,otherButtonTitles可设置多个button
UIAlertView *alert = [[UIAlertViewalloc]initWithTitle:@"温馨提示" message:@"你要选择点击哪一个" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定"];
[alert show];
[alert release]
//代理方法
-(void)alertView:(UIAlertView *)alertViewclickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLong(@”你点击的是第%d个”, buttonIndex);
}
2.UIActionSheet
UIActionSheet *actionSheet =[[UIActionSheet alloc] initWithTitle:@"温馨提示" delegate:self cancelButtonTitle:@"取消"
destructiveButtonTitle:@"确定" otherButtonTitles:@"待定"];
[actionSheet showInView:self.view];
[actionSheet release];
//代理方法
- (void)actionSheet:(UIActionSheet*)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
NSLog(@"点击了第%d个", buttonIndex);
if (buttonIndex == actionSheet.cancelButtonIndex) {
return;
}
switch (buttonIndex) {
case 0: {
NSLog(@"你点击了确定");
break;
}
case 1: {
NSLog(@"你点击了待定");
break;
}
}
}
3.UIAlertController
// preferredStyle设置弹窗样式,本文用的是UIAlertControllerStyleAlert,具体可根据实际要求选择
UIAlertController *alertcontroller =[UIAlertController alertControllerWithTitle:@"温馨提示"message:@"你已经进入警告区域" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction*action = [UIAlertAction actionWithTitle:@"确定"style:UIAlertActionStyleDefault handler:^(UIAlertAction * action)) {
NSLog(@"你点击了确定");
}];
UIAlertAction *action1 = [UIAlertActionactionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
NSLog(@"你点击了取消");
}];
[alertcontroller addAction:action];
[alertcontroller addAction:action1];
[self presentViewController:alertcontroller animated:YES completion:nil];
1.UIAlertView
// message 可设置为nil,cancelButtonTitle也可设置为nil,otherButtonTitles可设置多个button
UIAlertView *alert = [[UIAlertViewalloc]initWithTitle:@"温馨提示" message:@"你要选择点击哪一个" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定"];
[alert show];
[alert release]
//代理方法
-(void)alertView:(UIAlertView *)alertViewclickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLong(@”你点击的是第%d个”, buttonIndex);
}
2.UIActionSheet
UIActionSheet *actionSheet =[[UIActionSheet alloc] initWithTitle:@"温馨提示" delegate:self cancelButtonTitle:@"取消"
destructiveButtonTitle:@"确定" otherButtonTitles:@"待定"];
[actionSheet showInView:self.view];
[actionSheet release];
//代理方法
- (void)actionSheet:(UIActionSheet*)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
NSLog(@"点击了第%d个", buttonIndex);
if (buttonIndex == actionSheet.cancelButtonIndex) {
return;
}
switch (buttonIndex) {
case 0: {
NSLog(@"你点击了确定");
break;
}
case 1: {
NSLog(@"你点击了待定");
break;
}
}
}
3.UIAlertController
// preferredStyle设置弹窗样式,本文用的是UIAlertControllerStyleAlert,具体可根据实际要求选择
UIAlertController *alertcontroller =[UIAlertController alertControllerWithTitle:@"温馨提示"message:@"你已经进入警告区域" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction*action = [UIAlertAction actionWithTitle:@"确定"style:UIAlertActionStyleDefault handler:^(UIAlertAction * action)) {
NSLog(@"你点击了确定");
}];
UIAlertAction *action1 = [UIAlertActionactionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
NSLog(@"你点击了取消");
}];
[alertcontroller addAction:action];
[alertcontroller addAction:action1];
[self presentViewController:alertcontroller animated:YES completion:nil];
相关文章推荐
- iOS中UIAlertView警告框组件的使用教程
- iOS中的表单按钮选项UIActionSheet常用方法整理
- 在 Swift 中测试 UIAlertController的方法
- iphone:自定义UIAlertView
- 在iOS 8中使用UIAlertController
- 设置弹框
- iOS弹窗UIAlertController的使用
- UIAlertController iOS8弹出菜单用法
- [Swift]UIKit学习之警告框:UIAlertController和UIAlertView
- 兼容iOs7的自定义alertView
- iOS8新特性 UIPresentationController(一)
- iOS 8 UIAlertController 控件
- 关于UIAlertController的使用(swift)
- 在iOS 8中使用UIAlertController
- UIAlertView头文件学习
- UIAlertView的基本使用和对话框中按钮的事件处理方法
- UIButton,UIAlertView
- iOS最好用的弹出框
- (原创)iOS tableview系统左滑删除 左滑置顶 自定义左滑事件功能 输入框弹出
- 获取UIAlertController中textField的值