You can do as :
In .h I have an outlet called previousTextField
which is hooked to the first one. As name suggests it will store the latest added textField.
Find running project here.
-(IBAction)addTextField:(id)sender{
float x=previousTextField.frame.origin.x;
float y=previousTextField.frame.origin.y+50;//get y from previous textField and add 10 or so in it.
float w=previousTextField.frame.size.width;
float h=previousTextField.frame.size.height;
CGRect frame=CGRectMake(x,y,w,h);
UITextField *textField=[[UITextField alloc] initWithFrame:frame];
textField.placeholder = @"Enter User Name or Email";
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.font = [UIFont systemFontOfSize:15];
textField.autocorrectionType = UITextAutocorrectionTypeNo;
textField.keyboardType = UIKeyboardTypeDefault;
textField.returnKeyType = UIReturnKeyDone;
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
[self.view addSubview:textField];
previousTextField=textField;
}
Just an idea/algorithm how to go with, not compiler checked
I missed on thing, changing the location of + button. I think you can do it :)
EDIT: add following in above method
//move addbutton which is an outlet to the button
CGRect frameButton=CGRectMake(addButton.frame.origin.x, addButton.frame.origin.y+50, addButton.frame.size.width, addButton.frame.size.height);
[addButton removeFromSuperview];
[addButton setFrame:frameButton];
[self.view addSubview:addButton];
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…