UIAlertView_带文本输入框的提示框

来源:互联网 发布:带网络变压器的rj45 编辑:程序博客网 时间:2024/06/05 23:29

这里写图片描述

UIButton* btn = [UIButton buttonWithType:UIButtonTypeCustom];    btn.frame = CGRectMake(0, 20, 60, 40);    btn.backgroundColor = [UIColor grayColor];    [btn setTitle:@"按钮" forState:UIControlStateNormal];    [btn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];    [self.view addSubview:btn];    UIAlertView* alertView = [[UIAlertView alloc]initWithTitle:@"温馨提示" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];    alertView.tag = 1;    //设置提示框的类型    alertView.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;    [self.view addSubview:alertView];

调用的方法:

-(void)btnAction:(UIButton*)sender{    UIAlertView* alertView = [self.view viewWithTag:1];    [alertView show];}-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{    //通过索引值找到账号文本输入框    if (buttonIndex == 1) {        UITextField* textField = [alertView textFieldAtIndex:0];        //通过索引值找到密码文本输入框        UITextField* textField1 = [alertView textFieldAtIndex:1];        NSLog(@"账号:%@ 密码:%@",textField.text,textField1.text);    }
原创粉丝点击