UIAlertController
来源:互联网 发布:数据库编程技术 编辑:程序博客网 时间:2024/05/16 15:18
iOS8以后苹果就推荐用UIAlertController来创建提示框了,UIAlertCotroller也是iOS8以后才可以用的
{
// 创建一个alertContoller对象,其中Style参数是传入你要创建的是alertView还是ActionSheet
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"签名" message:@"\n" preferredStyle:UIAlertControllerStyleAlert];
// 取消按钮 UIAlertActionStyleCancel
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancelhandler:^(UIAlertAction *action) {
NSLog(@"我是取消按钮");
}];
// 其他按钮 UIAlertActionStyleDefault
UIAlertAction *otherAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefaulthandler:^(UIAlertAction *action) {
NSLog(@"我是确定按钮");
}];
// 描述的红色按钮 UIAlertActionStyleDestructive
UIAlertAction *destructive = [UIAlertAction actionWithTitle:@"描述" style:UIAlertActionStyleDestructivehandler:^(UIAlertAction *action) {
NSLog(@"我是红色按钮");
}];
// 将创建的alertAction添加到alertController中,其中取消按钮一直都是在最底部,其他按钮的顺序按添加顺序
[alertController addAction:cancelAction];
[alertController addAction:otherAction];
[alertController addAction:destructive];
// 添加textField输入框,可以在block中修改textField的属性
__weak ViewController *wself = self;
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.backgroundColor = [UIColor redColor];
[textField addTarget:wself action:@selector(textFieldDidChange:)forControlEvents:UIControlEventEditingChanged];
textField.placeholder = @"请输入用户名";
}];
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.secureTextEntry = YES;
textField.placeholder = @"请输入密码";
}];
// 展示alertController
[self presentViewController:alertController animated:NO completion:^{
}];
}
// 检测textField的文本变化
- (void)textFieldDidChange:(UITextField *)textField
{
NSLog(@"%@", textField.text);
}
其中如果是ActionSheet的话,不能添加textField属性
- UIAlertController
- UIAlertController
- UIAlertController
- UIAlertController
- UIAlertController
- UIalertController
- UIAlertController
- UIalertController
- UIAlertController
- UIAlertController
- UIAlertController
- UIAlertController
- UIAlertController
- UIAlertController
- UIAlertController
- UIAlertController
- UIAlertController
- UIAlertController
- Java多线程中的10个面试要点
- 安卓实现代码混淆
- 什么是NP问题,什么是NP hard问题,什么是NP完全问题。
- JAVA常用设计模式(3)观察者模式
- Qt::FocusPolicy的使用
- UIAlertController
- JavaScript之对数组中元素进行增删改
- 逻辑回归及梯度下降
- 开-闭原则(OCP - Open-Closed Principle )
- DTO(数据传输对象)
- Android SystemProperties设置/取得系统属性的用法总结
- Ajax-Ajax基础实例
- H5获取地理位置
- Linux下挂载与解除挂载U盘