Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- newSize = [_cell.detailedTextView sizeThatFits:CGSizeMake(CGRectGetWidth(_cell.detailedTextView.bounds), CGRectGetHeight(_cell.detailedTextView.bounds))];
- + (CGFloat)gettextViewHeight:(UITextView*)textView
- {
- CGSize constraint = CGSizeMake(textView.frame.size.width, 20000.0f);
- CGSize size;
- NSStringDrawingContext *context = [[NSStringDrawingContext alloc] init];
- CGSize boundingBox = [textView.text boundingRectWithSize:constraint
- options:NSStringDrawingUsesLineFragmentOrigin
- attributes:@{NSFontAttributeName:textView.font}
- context:context].size;
- size = CGSizeMake(ceil(boundingBox.width), ceil(boundingBox.height));
- return size.height;
- }
- func height(of string: String, in textView: UITextView) -> CGFloat
- {
- let font = textView.font ?? UIFont.preferredFont(forTextStyle: .headline)
- let width = textView.bounds.size.width - 2.0 * textView.textContainer.lineFragmentPadding
- let size = CGSize(width: width,
- height: CGFloat.greatestFiniteMagnitude)
- let height = string.boundingRect(with: size,
- options: [.usesLineFragmentOrigin, .usesFontLeading],
- attributes: [NSAttributedString.Key.font: font],
- context: nil).size.height
- let insets = textView.textContainerInset.top + textView.textContainerInset.bottom
- let diff = ceil(font.ascender - font.capHeight)
- return height + insets + diff
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement