iOS开发 - UIAlertController 弹框提醒
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了iOS开发 - UIAlertController 弹框提醒,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3334字,纯文字阅读大概需要5分钟。
内容图文
![iOS开发 - UIAlertController 弹框提醒](/upload/InfoBanner/zyjiaocheng/1185/f006e13255bc409091c0b29a2a66942b.jpg)
传统的alertView
- (void)alertView
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"警告" message:@"你的操作时非法的,您要继续吗" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
alert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
[alert show];
}
传统的actionSheet
- (void)actionSheet
{
UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"警告:你的操作时非法的,您要继续吗" delegate:nil cancelButtonTitle:@"取消" destructiveButtonTitle:@"确定"
otherButtonTitles:@"关闭", nil];
[sheet showInView:self.view];
}
UIAlertController == UIAlertView + UIActionSheet
- (void)alertController
{
// 危险操作:弹框提醒// 1.UIAlertView// 2.UIActionSheet// iOS8开始:UIAlertController == UIAlertView + UIActionSheet
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"警告" message:@"你的操作时非法的,您要继续吗" preferredStyle:UIAlertControllerStyleAlert];
// 添加按钮
__weak typeof(alert) weakAlert = alert;
[alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
NSLog(@"点击了确定按钮--%@-%@", [weakAlert.textFields.firstObject text], [weakAlert.textFields.lastObject text]);
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
NSLog(@"点击了取消按钮");
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"其它" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
NSLog(@"点击了其它按钮");
}]];
// 添加文本框
[alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.textColor = [UIColor redColor];
textField.text = @"123";
[textField addTarget:self action:@selector(usernameDidChange:) forControlEvents:UIControlEventEditingChanged];
// [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(usernameDidChange:) name:UITextFieldTextDidChangeNotification object:textField];
}];
[alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.secureTextEntry = YES;
textField.text = @"123";
}];
[self presentViewController:alert animated:YES completion:nil];
}
- (void)usernameDidChange:(UITextField *)username
{
NSLog(@"%@", username.text);
}
其他操作
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"警告" message:@"你的操作时非法的,您要继续吗" preferredStyle:UIAlertControllerStyleActionSheet];
// 设置popover指向的item
alert.popoverPresentationController.barButtonItem = self.navigationItem.leftBarButtonItem;
// 添加按钮
[alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
NSLog(@"点击了确定按钮");
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
NSLog(@"点击了取消按钮");
}]];
[self presentViewController:alert animated:YES completion:nil];
}
// UIAlertControllerStyleActionSheet的使用注意// 1.不能有文本框// 2.在iPad中,必须使用popover的形式展示// Text fields can only be added to an alert controller of style UIAlertControllerStyleAlert// 只能在UIAlertControllerStyleAlert样式的view上添加文本框
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文:http://blog.csdn.net/wangzi11322/article/details/48103425
内容总结
以上是互联网集市为您收集整理的iOS开发 - UIAlertController 弹框提醒全部内容,希望文章能够帮你解决iOS开发 - UIAlertController 弹框提醒所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。