创建IOS的alert界面
来源:互联网 发布:中文域名交易平台 编辑:程序博客网 时间:2024/06/06 08:43
//// MyViewController.m// Demo6_Alert警告框//// //#import "MyViewController.h"@interface MyViewController ()@end@implementation MyViewController- (IBAction)buttonClick:(id)sender { //需要弹出警告框 //1.创建UIAlertController实例 UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"title" message:@"message" preferredStyle:UIAlertControllerStyleAlert]; //2.创建意图按键 UIAlertAction *actionYES = [UIAlertAction actionWithTitle:@"YES" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { //把AlertController中所有的 textField取出 NSArray *fields = alert.textFields; //把 第一个添加的 textField取出 UITextField *userNameField = fields[0]; //把 第二个添加的 textField取出 UITextField *pwdField = fields[1]; //判断用户名是否是 abc 密码 是否是 123 if ([userNameField.text isEqualToString:@"abc"] && [pwdField.text isEqualToString:@"123"]) { //点钟action后做什么事情 NSLog(@"登录成功"); //重新弹出一个对话框, title 提示 message 登录成功 action 确定 }else { NSLog(@"登录失败"); } }]; UIAlertAction *actionNO = [UIAlertAction actionWithTitle:@"NO" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { NSLog(@"actionNO 被点中"); }]; //3.将 alertAction 添加到 AlertController中 [alert addAction:actionYES]; [alert addAction:actionNO]; //4.向AlertController中添加textField [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) { //在bolck中可以设置 今天添加的textField进行设置 //设置 占位符 textField.placeholder = @"请重新输入用户名"; }]; [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) { textField.textColor = [UIColor redColor]; textField.placeholder = @"请重新输入密码"; textField.secureTextEntry = YES;//密码样式 }]; //5.显示AlertController [self presentViewController:alert animated:YES completion:nil]; }- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib.}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}/*#pragma mark - Navigation// In a storyboard-based application, you will often want to do a little preparation before navigation- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller.}*/@end
0 0
- 创建IOS的alert界面
- iOS禁用webivew的alert
- IOS9.0中Alert的创建
- IOS 代码创建UI界面
- IOS:创建后台文件用于保存界面输入的信息
- iOS dev (9) 创建一个空白的界面
- IOS 自动关闭的Alert窗口
- iOS Automation关于Alert的处理
- iOS Automation关于Alert的处理
- 用IOS做一个界面切换的效果(登录界面和注册界面和找回密码界面的切换)(用封装好的lable和textf创建界面)
- 角色创建界面的创建
- 解决iOS中使用UIWebView加载嵌入脚本中带有alert时卡住界面问题。
- iOS 设置界面(纯代码创建)
- IOS(swift)中用代码创建UI界面
- iOS MAC终端界面 ~ 创建数据库sqlite3
- iOS alert sheet 样例
- ios中Alert提示框的简单使用
- 去除ios移动端alert/confirm的网址(url)
- Smack实现XMPP即时通信--登录,注册,发送及接收消息
- python多重赋值理解
- [C\C++]读入优化【技巧】
- JobClient
- YTUOJ之判断是否是子串(串)
- 创建IOS的alert界面
- ACM内部函数--数学问题--任意进制转换
- STM32系列第21篇--DMA
- HDU 3068:最长回文【回文字符串】
- SDOI2016 Round 1解题报告
- 第7周-项目2-友元类
- myeclipse编码问题
- nyoj 1091 还是01背包
- ios修改导航栏的title的文字颜色