查看我的代码的输出..
您可以使用以下代码...我已经完成并且它正在按照您的屏幕截图运行..
在你的 .h 文件中声明这个变量
int newY,newY1;
UIButton *btn;
然后您的 .m 文件在 viewDidLoad 方法中添加以下代码
UITextField *txt=[[UITextField alloc]init];
txt.frame=CGRectMake(50,30,140,30);
txt.placeholder = @"Enter User Name or Email";
txt.borderStyle = UITextBorderStyleRoundedRect;
[self.view addSubview:txt];
newY=txt.frame.origin.y;
btn=[UIButton buttonWithType:UIButtonTypeContactAdd];
btn.frame=CGRectMake(250,30, 30, 30);
[btn addTarget:self action:@selector(addtxtField) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
& 然后创建一个 addtxtField 方法..见下文
-(void)addtxtField
{
newY=newY+50;
UITextField *nwtxt=[[UITextField alloc]init];
nwtxt.frame=CGRectMake(50,newY,140,30);
nwtxt.placeholder = @"Enter User Name or Email";
nwtxt.borderStyle = UITextBorderStyleRoundedRect;
[self.view addSubview:nwtxt];
btn.frame=CGRectMake(250,newY, 30, 30);
[self.view addSubview:btn];
}
它是 100% 根据您的要求运行...