- 声明和使用方法(标准的Alert样式)
//UIAlertController风格:UIAlertControllerStyleAlert
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"没有标题的标题"
message:@"学无止境,漫漫长路"
preferredStyle:UIAlertControllerStyleAlert ];
//添加取消到UIAlertController中
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:nil];
[alertController addAction:cancelAction];
//添加确定到UIAlertController中
UIAlertAction *OKAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
[alertController addAction:OKAction];
[self presentViewController:alertController animated:YES completion:nil];
- 声明和使用方法(标准的Alert Sheet样式)
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"标准的Action Sheet样式"
message:nil
preferredStyle:UIAlertControllerStyleActionSheet];
//取消:style:UIAlertActionStyleCancel
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
[alertController addAction:cancelAction];
//了解更多:style:UIAlertActionStyleDestructive
UIAlertAction *moreAction = [UIAlertAction actionWithTitle:@"了解更多" style:UIAlertActionStyleDestructive handler:nil];
[alertController addAction:moreAction];
//原来如此:style:UIAlertActionStyleDefault
UIAlertAction *OKAction = [UIAlertAction actionWithTitle:@"原来如此" style:UIAlertActionStyleDefault handler:nil];
[alertController addAction:OKAction];
[self presentViewController:alertController animated:YES completion:nil];
- UIAlertActionStyle三种类型
style:UIAlertActionStyleDefault//对按钮应用标准样式
style:UIAlertActionStyleCancel//对按钮应用取消样式,即取消操作
style:UIAlertActionStyleDestructive//对按钮应用警示性样式,提示用户这样做可能会删除或者改变某些数据
网友评论