使用旧UITextview上方的新UITextView动态添加多个UITextview

时间:2014-03-28 07:27:10

标签: ios iphone uitextview autolayout

我有一个UITextView用于为文章添加评论。 UITextView下面的UIButton名为'添加另一个评论'。在点击此UIButton时,必须创建另一个UITextView,以便旧的UITextView被推到新的UITextView之下。我必须能够做到这一点,我想要多少次。

编辑:我的问题不在于创建{{1}},而是将旧文本视图推送到新文本视图下方。这应该是这样的:

a)在打开评论部分之前

enter image description here

b)打开评论部分后

2 个答案:

答案 0 :(得分:0)

嗨John是的,你可以点击按钮后创建uitextfield,你必须编写代码,如下所示

- (IBAction)addText:(id)sender
{
CGRect textfieldFrame = CGRectMake(0.0, 0.0, 100.0, 30.0);
UITextField *textField = [[UITextField alloc] initWithFrame:textfieldFrame];
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.font = [UIFont systemFontOfSize:15];
textField.placeholder = @"enter text";
textField.autocorrectionType = UITextAutocorrectionTypeNo;
textField.keyboardType = UIKeyboardTypeDefault;
textField.returnKeyType = UIReturnKeyDone;
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;    
textField.delegate = self;
[self.view addSubview:textField];



}

this link also use full for the reference

答案 1 :(得分:0)

只需更改动态块

中旧文本视图的y位置即可

[UIView animateWithDuration:1.0动画:^ {

// set center = btn.y + btn height + 0.5 * tetview height +如果你想要的话,按钮下面的任何空格

}];

我很怀疑 正在使用滚动视图?用户将如何看待之前的评论?如果文本高度大于textview的高度怎么办?