点击按钮输入附件视图

时间:2014-02-10 03:29:01

标签: ios ios7 uitextfield uikeyboard inputaccessoryview

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

enter image description here

我已经尝试过但却无法得到类似的东西。我该如何制作这样的东西?

2 个答案:

答案 0 :(得分:0)

你应该使用这样的东西:

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

答案 1 :(得分: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];

}