-4

是否可以创建动态UITextField,例如当用户单击文本字段进行编辑时,它会自动UITextFieldUITextField.

4

4 回答 4

0

创建一个新的文本字段,如:

UITextField *myTextField = [[UITextField alloc] initWithFrame:CGRectMake(75,210,265,30)];
myTextField.placeholder=@"Enter Label Here";
myTextField.font =[UIFont systemFontOfSize:25];
myTextField.clearButtonMode=UITextFieldViewModeWhileEditing;
[self.view addSubView:myTextField];

您需要根据您的要求更改框架。

于 2012-11-06T05:28:11.807 回答
0

只需将此代码添加到您的 .m 文件中,或者只需在您的textFieldShouldBeginEditing:方法中添加以下代码

 - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
    UITextField *txtTemp=[[UITextField alloc]initWithFrame:CGRectMake(yourTextField.frame.origin.x, yourTextField.frame.origin.y + 50, yourTextField.frame.size.width, yourTextField.frame.size.height)];
    txtTemp.delegate = self;
    [self.view addSubview:txtTemp];
    return YES;
}
于 2012-11-06T05:29:33.380 回答
0

是的。这里在

-(void)textFieldDidBeginEditing:(UITextField *)textField

UITextField根据原始框架分配另一个UITextField,如果要添加多个文本字段,请将分配循环。希望这可以帮助。

于 2012-11-06T05:29:29.937 回答
-1

实施UITextFieldDelegate

- (void)textFieldDidBeginEditing:(UITextField *)textField{    

      if(textField == firstTextFeild){

          //Create secondTextFeild.
   }

}
于 2012-11-06T05:29:31.213 回答