gpt4 book ai didi

iphone - 动态插入更多 UITextFields

转载 作者:行者123 更新时间:2023-11-28 19:11:00 26 4
gpt4 key购买 nike

我有一个要求,如所附屏幕截图中所述。单击蓝色添加按钮时,必须在最后一个文本字段和 TextView 之间再插入一个 UItextfield,并且蓝色添加按钮必须出现在动态插入的新 uitextfield 旁边。任何人都可以建议如何实现这一目标。我已将所有字段放在 UIScrollview 中。

enter image description here

ScrollView 未启用:

enter image description here

最佳答案

你可以这样做:

在 .h 中,我有一个名为 previousTextField 的导出,它连接到第一个导出。顾名思义,它将存储最新添加的文本字段。

查找运行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;
}

只是一个想法/算法如何进行,未经编译器检查

我错过了一件事情,正在更改 + 按钮的位置。我认为你可以做到:)

编辑:在上述方法中添加以下内容

//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];

关于iphone - 动态插入更多 UITextFields,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15539690/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com