UIAlertControlle有两种preferredStyle
1.UIAlertControllerStyleAlert 是在中间显示的
2.UIAlertControllerStyleActionSheet是在下面显示的
//设置Title、message 、preferredStyle
UIAlertController *controller = [UIAlertController alertControllerWithTitle:@"通知" message:@"消息消息消息消息消息消息" preferredStyle:UIAlertControllerStyleActionSheet];
添加按钮 一共三种样式
1.UIAlertActionStyleCancel
2.UIAlertActionStyleDestructive
3.UIAlertActionStyleDefault
//1.UIAlertActionStyleCancel
UIAlertAction *cancelAciton = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"点击了取消");
}];
//2.UIAlertActionStyleDestructive
UIAlertAction *okAciton = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"点击了确定");
}];
3.UIAlertActionStyleDefault
UIAlertAction *yesAciton = [UIAlertAction actionWithTitle:@"是" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"点击了是");
}];
将Action添加到controller
[controller addAction:cancelAciton];
[controller addAction:okAciton];
[controller addAction:yesAciton];
显示提醒
[self presentViewController:controller animated:YES completion:nil];
网友评论