2012-11-06 25 views
-4

是否有可能創建動態UITextField,就像用戶單擊要編輯的文本字段時一樣,它會自動創建另一個UITextField,低於UITextField動態UITextField創建

+0

使用代碼,我張貼在答案准確創建動態文本的文本框下,當文本字段開始編輯.. –

+1

不問任何例子。使用給定的提示以自己的方式嘗試使用 –

+2

您需要提高搜索能力......堆棧溢出包含許多關於「如何創建動態對象」的示例。 –

回答

-1

實施UITextFieldDelegate

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

     if(textField == firstTextFeild){ 

      //Create secondTextFeild. 
    } 

} 
+0

secondTextFeild框架應該像secondTextFeild.frame = CGRectMake(firstTextFeild.frame.origin.x,(firstTextFeild.frame.origin.y + firstTextFeild.frame.size.height)+ 10,firstTextFeild.frame.size.width,firstTextFeild。 frame.size.height); –

0

創建一個新的文本字段一樣:

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

您需要根據您的要求來改變框架。

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; 
} 
0

是添加婁代碼。在這裏,在

-(void)textFieldDidBeginEditing:(UITextField *)textField 

分配另一個UITextField按原UITextField的框架,如果你想添加多個文本框把分配在一個循環。希望這可以幫助。