iOS UIalertcontroller的简单使用

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];

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容