2013-10-29 53 views
0

我有一个scrollview。我在同一行放置了一个textfield和一个按钮。我希望当用户在textbox中输入URL并点击button时,URL应该被添加动态地创建textview而不是textboxbutton。 (我正在使用textview,因为它会自动检测URL并作为链接显示)。 我已经尝试下面的代码,但它不工作:动态添加textview点击按钮中的ios目标c

- (IBAction)addLinkClicked:(id)sender { 

    NSLog(@"Add Link button clicked"); 
    UITextView *linkTextView = [[UITextView alloc] init]; 
    linkTextView.text = @"http://google.com"; 
    linkTextView.layer.cornerRadius = 5.0; 
    [self.scrollView addSubview:linkTextView]; 
} 

2.

- (IBAction)addLinkClicked:(id)sender { 

    NSLog(@"Add Link button clicked"); 
    UITextView *linkTextView = [[UITextView alloc] init]; 
    linkTextView.text = @"http://google.com"; 
    linkTextView.layer.cornerRadius = 5.0; 
    [self.scrollView insertSubview:linkTextView atIndex:[self.scrollView.subviews count]]; 
} 

请帮我解决我的问题。

+0

设置UITextView框架 – Mutawe

回答

1

我的朋友,你需要设置为UITextFiled框架...

你有两种可能的方式:

UITextView *linkTextView = [[UITextField alloc] initWithFrame:CGRectMake(x, y, width, height)] 

或者

UITextView *linkTextView = [[UITextView alloc] init]; 
linkTextView.frame = CGRectMake(x, y, width, height); 

干杯!

+0

这是评论不是答案。 – Jitendra

0

设置为TextView的框架:以上

linkTextView = [[UITextView alloc] initWithFrame:CGRectMake(240, 35, 70, 20)]; //put the values you want 
0

两个问题的答案是相同的,是正确的。只需一个备用答案,当您创建textfieldbutton并将hidden属性设置为true时,也可以在同一帧中添加textview。轻触button后,隐藏textfieldbutton,并通过将hidden设置为false来显示文本视图。

相关问题