我在 ScrollView 上使用 UITextView ...我希望它在我写东西时自动扩展......但我无法做到......
textViewBusiness = [[UITextView alloc] initWithFrame:CGRectMake(25,332,268,60)];
textViewBusiness.text=strMyBusiness;
textViewBusiness.editable=NO;
textViewBusiness.font = [UIFont fontWithName:@"Arial" size: 17.0];
textViewBusiness.layer.borderWidth = 2.0f;
textViewBusiness.layer.borderColor = [[UIColor grayColor] CGColor];
textViewBusiness.backgroundColor = [UIColor clearColor];
[textViewBusiness setTextColor:[UIColor blackColor]];
[self.scrollView addSubview: textViewBusiness];
CGRect frame = textViewBusiness.frame;
frame.size.height = textViewBusiness.contentSize.height;
textViewBusiness.frame = frame;
这段代码对我不起作用...
谢谢
最佳答案
确保设置了文本字段的委托(delegate)...
someTextField.delegate = self;
然后在相应的文本字段委托(delegate)方法中调整 textView 的大小。
- (void)textViewDidChange:(UITextView *)textView;
- (void) textViewDidEndEditing:(UITextView *)textView;
您在上面添加的代码是正确的。只要确保它在正确的位置。
- (void)textViewDidChange:(UITextView *)textView
{
CGRect frame = textView.frame;
frame.size.height = textView.contentSize.height;
textView.frame = frame;
}
Dynamic expand UITextView
关于ios - iPhone : UITextView not expanding while editing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10617381/