您的位置:首页 > 产品设计 > UI/UE

iOS 开发之带输入框的UIAlertView

2015-11-14 23:31 246 查看
//

//  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



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: