ios - iPhone : UITextView not expanding while editing

标签 ios xcode4 uitextview

我在 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/

相关文章:

iphone - 路由音频输入以从 iPhone 上的 TOP 麦克风接收

ios - 如何在 UITextview 中的每一行前添加破折号 (-)?1

ios - 带有三个点的 UITextview 剪辑?

ios - 移动背景在 Spritekit 上停止重复

iphone - CGContextAddLineToPoint : no current point

iphone - 将静态库添加到一个项目时出错

swift - 我如何将文本从文本字段附加到 TextView 并每次快速换行?

php - 如何使用 AFNetworking 2.0 检查 Wordpress 登录信息?

javascript - 在IOS中实现JS功能

ios - UIView(或 UILabel ?),带有 Storyboard中另一个 View 的链接