美文网首页
tableViewCell中有textview时的高度

tableViewCell中有textview时的高度

作者: 神秘唤猫人 | 来源:发表于2017-03-11 16:10 被阅读52次

+ (CGRect)contentSizeRectForTextView:(UITextView *)textView

{

[textView.layoutManager ensureLayoutForTextContainer:textView.textContainer];

CGRect textBounds = [textView.layoutManager usedRectForTextContainer:textView.textContainer];

CGFloat width =  (CGFloat)ceil(textBounds.size.width + textView.textContainerInset.left + textView.textContainerInset.right);

CGFloat height = (CGFloat)ceil(textBounds.size.height + textView.textContainerInset.top + textView.textContainerInset.bottom);

return CGRectMake(0, 0, width, height);

}

这个方法, 就可以取到了

但是...如果你用了xib做cell, 并且! cell里有一上一下两个textview, 还是很蛋疼

只能把约束拖线出来, 算出高度,给约束的constant设值

相关文章

网友评论

      本文标题:tableViewCell中有textview时的高度

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