美文网首页
iOS UIalertcontroller的简单使用

iOS UIalertcontroller的简单使用

作者: 特喵了个咪的猫 | 来源:发表于2016-10-30 17:21 被阅读0次

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

相关文章

网友评论

      本文标题:iOS UIalertcontroller的简单使用

      本文链接:https://www.haomeiwen.com/subject/srkuuttx.html