標籤:
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 @endView Code
iOS9 警告框