gpt4 book ai didi

ios - 如何在单击添加按钮时动态添加新的文本字段

转载 作者:行者123 更新时间:2023-12-01 20:19:48 27 4
gpt4 key购买 nike

刚才我单击按钮时,我动态创建了文本字段
我的代码是:

-(void)clickonAdd
{
CGRect textfieldFrame = CGRectMake(18, 350,309,35.0);
UITextField *textField = [[UITextField alloc]initWithFrame:textfieldFrame];
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.font = [UIFont systemFontOfSize:15];
textField.placeholder = @"Select Item List";
textField.autocorrectionType = UITextAutocorrectionTypeNo;
textField.keyboardType = UIKeyboardTypeDefault;
textField.returnKeyType = UIReturnKeyDone;
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
textField.contentVerticalAlignment =UIControlContentVerticalAlignmentCenter;
textField.delegate = self;
[self.view addSubview:textField];
}

现在我想添加更多具有不同位置的文本框,当单击相同的按钮时...您能帮我吗...谢谢

最佳答案

尝试这个 ...

@interface ViewController ()
{
CGFloat y;
CGFloat x;
}

- (void)viewDidLoad
{
[super viewDidLoad];

y = 0;
x = 0;
}

-(void)clickButtonAdd
{
UITextField *textField;
textField.frame = CGRectMake(x, y,100,30);
textField = [[UITextField alloc]initWithFrame:textfieldFrame];
textField.borderStyle = UITextBorderStyleRoundedRect;
[self.view addSubview:textField];

x = x + 120;
y = y + 40;
}

关于ios - 如何在单击添加按钮时动态添加新的文本字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35889101/

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