ios9新增 UIAlertController 简单用法
来源:互联网 发布:linux 安装内核源码 编辑:程序博客网 时间:2024/05/21 22:41
// 一 .创建 UIalertController继承于UIViewController
// 1.创建UIAlertController
// 2.初始化UIAlertController,需要使用alertControllerWithTitle:message:preferredStyle:方法;
// 3.设置Title 、message、preferredStyle;
// 4.preferredStyle风格样式有两种:UIAlertControllerStyleAlert和UIAlertControllerStyleActionSheet,是分别代替UIalertView和UIActionSheet的;
// 第一种 UIAlertControllerStyleAlert(屏幕的中间)
// UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"标题" message:@"UIAlertController" preferredStyle:UIAlertControllerStyleAlert];
//
// 提示框是 模态 产生的
// [self presentViewController:alertController animated:YES completion:nil];
// 使用NSLocalizedString本地化(宏)
// 第一个参数key是从Localizable.strings这个文件中读取对应的key-value值
// 第二个参数comment可以是nil,可以是一段为空的字符串,也可以是对key的注释
// 初始化 的不同方法
// preferred [pri'fə:d] 首选的
// NSString *title = NSLocalizedString(@"A short is best ", @"标题");
// NSString *messge = NSLocalizedString(@"A messgea should be a shaort", nil);
// UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:messge preferredStyle:UIAlertControllerStyleAlert];
//模态
// [self presentViewController:alertController animated:YES completion:nil];
//第二种 UIAlertControllerStyleActionSheet(屏幕的底部)
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"标题" message:@"UIAlertController" preferredStyle:UIAlertControllerStyleActionSheet];
// 二. 显示UIAlertController
// 1. UIAlertController继承于UIViewController;
// 2. 显实需要使用UIviewController的方法:presentViewController弹出试图控制器.
//模态
[self presentViewController:alertController animated:YES completion:nil];
// 三 . 添加按钮到UIAlertController
// 1. 创建UIAlertAction 作为 UIalertController的按钮项;
// 2. 初始化方法 : actionWithTitle:style:handler: ;
// 3. 设置Title style handler;
// 4. 添加 UIAlertAction 到 UIAlertController.
/*
******添加按钮
Title :标题名称
style :样式[Cancle(取消) Default(默认的) destructive(重置)]
handler:处理程序(点击按钮执行的代码)
*/
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
//添加 点击事件
self.view.backgroundColor = [UIColor yellowColor];
}];
UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:@"默认default" style:UIAlertActionStyleDefault handler:nil];
// “警示”样式
UIAlertAction *destructiveAction = [UIAlertAction actionWithTitle:@"重置deatructive" style:UIAlertActionStyleDestructive handler:nil];
[alertController addAction:cancelAction];
[alertController addAction:defaultAction];
[alertController addAction:destructiveAction];
// UIAlertAction 继承于NSObject
UIAlertAction *getAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
// UITextField *login = alertController.textFields[0];
// UITextField *passWord = alertController.textFields[1];
// [self.view endEditing:YES];
NSLog(@"密码");
}];
// ****** 注意: 要把按钮(UIAlertAction)加到alertController上
[alertController addAction:getAction];
// Do any additional setup after loading the view.
//三 . 添加文本输入框
//1. 文本输入框只能添加到Alert的风格中,ActionSheet是不允许的
//2.UIAlertController具有只读属性的textFiekds数组,可以按照自己需要的顺序添加;
//3.添加方式需要block,参数是UItextField;
//4.添加UItextField监听方法和实现方法
//添加输入文本输入框,已登录和密码对话框的形式
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = @"登陆";
// 如果要监听UITextFiled开始,结束,改变状态,则需要添加监听代码
// 1.添加通知,监听textfield内容的改变
// NSNotificationCenter 是一种 消息通信机制
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(alertTextFieldDidChange:) name:UITextFieldTextDidChangeNotification object:textField];
textField.backgroundColor = [UIColor orangeColor];
}];
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = @"密码"; // 占位字
textField.secureTextEntry = YES; //密文输入
}];
// 如果要监听UITextFiled开始,结束,改变状态,则需要添加监听代码
// 1.添加通知,监听textfield内容的改变
// [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
// textField.placeholder = @"添加监听";
// [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(alertTextFieldDidChange:) name:UITextFieldTextDidChangeNotification object:textField];
// }];
0 0
- ios9新增 UIAlertController 简单用法
- iOS9 UIAlertController简单使用代码
- ios9 xcode7 UIAlertController的常用用法
- iOS9 升级后UIAlertController的简单使用
- ios9开发之UIAlertController
- IOS8 新增UIAlertController类
- IOS9新增UIStackView
- iOS 9 UIAlertController 简单的介绍和用法
- UIAlertController简单用法(instead of UIAlertView||UIActionSheet)
- Android Dialog仿ios9中UIAlertController控件
- iOS9 新增特性(汇)
- UIAlertController的用法
- UIAlertController用法大全
- UIAlertController的用法示例
- iOS - UIAlertController相关用法
- UIAlertController的用法
- UIAlertController详解及用法
- UIAlertController的用法
- Logistic Regression
- J2EE学习顺序
- VPS 及配置指南
- 把pdf转换成html格式的转换方法分享
- 为什么这里跳不出循环?(无关代码已省略)
- ios9新增 UIAlertController 简单用法
- 解决安装tomcat服务出错:failed to install tomcat6 service
- 边听边记-创业分子-互联网颠覆医疗
- 关于数组名作为指针的问题
- 基于Dubbo框架构建分布式服务
- [bzoj4300][绝世水题]
- 零碎知识-控件类
- pdf2swf process阻塞问题
- iOS 创建单例