boundingRectWithSize 计算高度不准确.
CGSize size = [self.mode.desc boundingRectWithSize:CGSizeMake(ScreenWidth-8*2-self.wenTiTextView.textContainer.lineFragmentPadding, 0) options:NSStringDrawingUsesFontLeading | NSStringDrawingUsesLineFragmentOrigin attributes:@{ NSFontAttributeName:[UIFontsystemFontOfSize:14] }context:nil].size;
self.wenTiTextView.text = self.mode.desc;
self.wenTiTextHeigth.constant=ceilf(size.height);
后面还需要 设置textView的间距
self.wenTiTextView.textContainerInset = UIEdgeInsetsZero;
self.wenTiTextView.contentInset = UIEdgeInsetsZero;
self.wenTiTextView.layoutMargins = UIEdgeInsetsZero;
最后显示没有问题.....
关键点有3个
1. 最大宽度要设置准确,除了减去marg 还需要减去 textView 的textContainer.lineFragmentPadding.
2.去文本的高度是要用 ceilf(size.height)
3.要设置textViewD的textContainerInset,contentInset 和layoutMargins 为UIEdgeInsetsZero