码迷,mamicode.com
首页 > 移动开发 > 详细

iOS9 警告框

时间:2015-11-12 19:54:56      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:

iOS9中警告框的使用。可以进行用户名和密码的输入,实现页面交互,下面是ViewController的全部代码。以前的错误也没有删除,以警示自己。

技术分享
 1 #import "ViewController.h"
 2 
 3 @interface ViewController ()
 4 @property(nonatomic, retain) UITextField* user;    // 用户名输入框
 5 @property(nonatomic, retain) UITextField* pwd;    // 密码输入框
 6 @end
 7 
 8 @implementation ViewController
 9 
10 - (void)viewDidLoad {
11     [super viewDidLoad];
12     self.button = [[UIButton alloc] initWithFrame:CGRectMake(0, 100, [[UIScreen mainScreen] bounds].size.width, 20)];
13     [self.button setTitle:@"跳转" forState:UIControlStateNormal];
14     [self.button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
15     [self.view addSubview:self.button];
16     [self.button addTarget:self action:@selector(clickMe:) forControlEvents:UIControlEventTouchUpInside];
17 
18 } 
19 -(void)clickMe:(id)sender{
20     
21     //初始化提示框;
22      UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"您确定是否解除锁定" preferredStyle: UIAlertControllerStyleAlert];
23     [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
24         textField.placeholder = @"请输入用户名";
25 //        UIView *myUserView = [[UIView alloc]initWithFrame:CGRectMake(22, 45, 240, 36)];
26 //        myUserView.backgroundColor =  [UIColor redColor];
27 //        self.user = [self createTextField:@"请输入用户名"
28 //                                   withFrame:CGRectMake(22, 45, 240, 36)];
29 //        [myUserView addSubview:self.user];
30     }];
31     [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
32         textField.placeholder = @"请输入密码";
33 //        self.pwd = [self createTextField:@"请输入密码"
34 //                                   withFrame:CGRectMake(22, 82, 240, 36)];
35     }];
36     [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
37         //点击按钮的响应事件;
38         NSLog(@"取消提示");
39     }]];
40     [alert addAction:[UIAlertAction actionWithTitle:@"是的" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
41         //点击按钮的响应事件;
42         NSLog(@"确定提示");
43     }]];
44     //弹出提示框;
45     [self presentViewController:alert animated:true completion:nil];
46 
47 }
48 //- (UITextField*)createTextField:(NSString*)placeholder withFrame:(CGRect)frame {
49 //    UITextField* field = [[UITextField alloc] initWithFrame:frame];
50 //    field.placeholder = placeholder;
51 //    field.secureTextEntry = YES;
52 //    //field.backgroundColor = [UIColor redColor];
53 //    field.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
54 //    
55 //    return field;
56 //}
57 - (void)didReceiveMemoryWarning {
58     [super didReceiveMemoryWarning];
59     // Dispose of any resources that can be recreated.
60 }
61 
62 @end
View Code

 

iOS9 警告框

标签:

原文地址:http://www.cnblogs.com/yelan/p/4959917.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!