如何在点击按钮时动态添加文本字段?
单击按钮文本字段时,应显示滚动视图。
任何人都可以解释我该怎么做?
答案 0 :(得分:1)
-(IBAction)buttonClicked:(id)sender
{
UIScrollView *scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
UITextField *textField=[[UITextField alloc]initWithFrame:CGRectMake(20, 20, 40, 21)];
[scrollView addSubview:textField];
[self.view addSubview:scrollView];
}
修改
如果不是动态的,
- (void)viewDidLoad
{
[super viewDidLoad];
UIScrollView *scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
UITextField *textField=[[UITextField alloc]initWithFrame:CGRectMake(20, 20, 40, 21)];
[scrollView addSubview:textField];
[self.view addSubview:scrollView];
[scrollView setHidden:YES];
}
-(IBAction)buttonClicked:(id)sender
{
[scrollView setHidden:NO];
}
答案 1 :(得分:0)
在Button动作中,您可以创建动态文本字段,并将它们创建到您的滚动视图.....
答案 2 :(得分:0)
您可以使用以下代码以编程方式添加文本字段..
UITextField * aTextfield = [[UITextField alloc] initWithFrame:frame]; // give your frame
aTextfield.borderStyle = UITextBorderStyleRoundedRect;
aTextfield.textColor = [UIColor blackColor];
aTextfield.font = [UIFont systemFontOfSize:17.0];
aTextfield.placeholder = @"Suchen";
aTextfield.backgroundColor = [UIColor clearColor];
aTextfield.autocorrectionType = UITextAutocorrectionTypeNo;
aTextfield.keyboardType = UIKeyboardTypeDefault;
aTextfield.returnKeyType = UIReturnKeySearch;
aTextfield.clearButtonMode = UITextFieldViewModeWhileEditing;
aTextfield.delegate = self;
[scrollview addSubview:aTextfield];
答案 3 :(得分:0)
看看我的代码。
http://rajneesh071.blogspot.in/2012/09/make-textfield-and-label-dynamically-in.html
根据这个,您可以在滚动视图中创建多个文本字段和标签,这样您就可以根据需要进行更改。