iOS 开发之带输入框的UIAlertView

//

//  ViewController.m

//  1114带输入框的UIAlertView

//

//  Created by weibiao on 15/11/14.

//  Copyright © 2015 weibiao. All rights reserved.

//


#import "ViewController.h"


@interface ViewController ()<UIAlertViewDelegate>

- (IBAction)btnClick:(id)sender;


@end


@implementation ViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    

    

}


- (IBAction)btnClick:(id)sender {

//    UIAlertViewStyle *alertV = [];

    UIAlertView *alertV = [[UIAlertView alloc] initWithTitle:@"登陆" message:@"请输入用户名和密码登陆系统" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];

    alertV.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;

    [alertV textFieldAtIndex:1].keyboardType = UIKeyboardTypeNumberPad;

    [alertV show];

}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {

    if (buttonIndex == 1) {

        // 获取UIAlertView中第一个输入框

        UITextField *loginTextField = [alertView textFieldAtIndex:0];

        // 获取UIAlertView中的第二个输入框

        UITextField *passwardTextField = [alertView textFieldAtIndex:1];

        // 拼接TextField字符串

        NSString *msg = [NSString stringWithFormat:@"您输入的用户名是:%@,密码是:%@",loginTextField.text,passwardTextField.text];

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:msg delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];

        [alert show];

    }

}


- (void)willPresentAlertView:(UIAlertView *)alertView {

    // 遍历UIalertView包含的全部子控件

    for (UIView *view in alertView.subviews) {

        // 如果该子控件是UILabel控件

        if ([view isKindOfClass:[UILabel class]]) {

            UILabel *label = (UILabel *)view;

            // UILabel的文字对齐方式设为左对齐

            label.textAlignment = NSTextAlignmentLeft;

        }

    }

}

@end

iOS 开发之带输入框的UIAlertView_第1张图片

你可能感兴趣的:(iOS 开发之带输入框的UIAlertView)