0

我在视图中有两个文本字段和一个按钮。在按钮单击中,我希望键盘显示并获取密码。我想创建一个如下所示的视图。

在此处输入图像描述

我已经尝试过,但无法得到类似的东西。我怎么能做这样的事情?

4

2 回答 2

0

你应该使用这样的东西:

- (IBAction)clickButton 
{
    [yourTextField becomeFirstResponder];
}
于 2014-02-10T03:41:43.900 回答
0

此代码未经测试。但您可以这样做

 - (IBAction)clickButton 
{
    [self createInputAccessoryView];
    [yourTextField becomeFirstResponder];
}

 -(void)createInputAccessoryView{

    UIToolbar *keyboardToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 44)];
    CGRect rect=CGRectMake(0, 0, 25, 25);

    UITextField *txtFeild1=[[UITextField alloc]initWithFrame:rect];
     UITextField *txtFeild2=[[UITextField alloc]initWithFrame:rect];
     UITextField *txtFeild3=[[UITextField alloc]initWithFrame:rect];
     UITextField *txtFeild4=[[UITextField alloc]initWithFrame:rect];

    [keyboardToolbar addSubview:txtFeild1];
    [keyboardToolbar addSubview:txtFeild2];
    [keyboardToolbar addSubview:txtFeild3];
    [keyboardToolbar addSubview:txtFeild4];

     [txtFeild1 setInputAccessoryView:keyboardToolbar];
    [txtFeild2 setInputAccessoryView:keyboardToolbar];
    [txtFeild3 setInputAccessoryView:keyboardToolbar];
    [txtFeild4 setInputAccessoryView:keyboardToolbar];

}
于 2014-02-10T05:23:51.483 回答