美文网首页
UITextView更具内容来改变高度

UITextView更具内容来改变高度

作者: WeiSL | 来源:发表于2017-01-02 21:23 被阅读0次

textView.delegate = self;

-(void)textViewDidChange:(UITextView *)textView{

static CGFloat maxHeight =60.0f;

CGRect frame = textView.frame;

CGSize constraintSize = CGSizeMake(frame.size.width, MAXFLOAT);

CGSize size = [textView sizeThatFits:constraintSize];

if (size.height<=frame.size.height) {

size.height=frame.size.height;

}else{

if (size.height >= maxHeight)

{

size.height = maxHeight;

textView.scrollEnabled = YES;  // 允许滚动

}

else

{

textView.scrollEnabled = NO;    // 不允许滚动

}

}

textView.frame = CGRectMake(frame.origin.x, frame.origin.y, frame.size.width, size.height);

}

相关文章

网友评论

      本文标题:UITextView更具内容来改变高度

      本文链接:https://www.haomeiwen.com/subject/vafgvttx.html