• iOS9 警告框


    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

     补充:取其中的用户名与密码的值,用alert.textFields[0].text。alert.textFields是一个数组。

  • 相关阅读:
    从JAVA看C#中volatile和synchronized关键字的作用
    SSAS动态添加分区 (转载)
    IIS7的集成模式下如何让自定义的HttpModule不处理静态文件(.html .css .js .jpeg等)请求
    SqlServer Analysis Service的事实维度关系
    SqlServer分区表概述(转载)
    SQL2005中的事务与锁定(九)-(1)- 转载
    SQL2005中的事务与锁定(八)- 转载
    SQL2005中的事务与锁定(七)
    LINUX下编译ffmpeg-x264出现的错误及解决转
    从ffmpeg源代码分析如何解决ffmpeg编码的延迟问题 (转)
  • 原文地址:https://www.cnblogs.com/yelan/p/4959917.html
Copyright © 2020-2023  润新知