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

UIActionSheet/ UIAlaterView/UIAlertController

2016-11-26 14:20 447 查看
UIActionSheet/ UIAlaterView 的区别是,

1 一个在屏幕底部弹出, 一个在屏幕正中间弹出.

2 按钮的序号不同. UIActionSheet 按钮的序号, 是从上往下, 依次 0,1,2…. UIAlaterView 按钮的序号 是 cancelButtonTitle是0 otherButtonTitles是 从1,2,3…

// 弹出来alertview ios7 以后中的另一种写法

//UIAlertControllerStyleAlert 可以选择是在底部,还是屏幕中间

UIAlertController *vc = [UIAlertController alertControllerWithTitle:@”提示” message:@”指纹识别” preferredStyle:UIAlertControllerStyleAlert];

//添加按钮


UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
[vc addAction:action1];


//红色字体的


UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
NSLog(@"queding");
}];
[vc addAction:action2];

[self presentViewController:vc animated:YES completion:nil];


通讯录 04 通讯录注销 第4分钟

在底部弹出一个警示框, 用于给用户提供选项, 如QQ 点击退出时在底部弹出的 确定/ 取消/ 退出后接收消息.

(IBAction)logout:(id)sender {

UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@”提示” delegate:self cancelButtonTitle:@”取消” destructiveButtonTitle:@”确定” otherButtonTitles:nil, nil];

//显示

[sheet showInView:self.view];

遵守代理 实现代理方法, 可以对点击按钮后进行对应操作.

pragma mark - actionSheet的代理方法

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0) {
//点了确定按钮   排序,从上往下 0,1,2…..
[self.navigationController popViewControllerAnimated:YES];
}
}


在屏幕正中央,弹出一个提示框,

UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"提示 " message:@"退出QQ ?" delegate:self cancelButtonTitle:@"不退出" otherButtonTitles:@"退出",@"暂停", nil];

[alertView show];


可以是两个选项, 也可以是三个选项.

UIAlaterView 按钮的序号(buttonIndex) 是 cancelButtonTitle(不退出)是0 otherButtonTitles是 从1,2,3…

代理方法

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(@"点击了%ld",(long)buttonIndex);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: