通过文字计算lab高度

 1   var attrButes:[NSAttributedString.Key : Any]! = nil;
 2         let paraph = NSMutableParagraphStyle()
 3         paraph.lineSpacing = 8
 4         attrButes = [NSAttributedString.Key.font:UIFont.systemFont(ofSize: 13.5),NSAttributedString.Key.paragraphStyle:paraph]
 5         
 6         let size:CGRect = model.content!.boundingRect(with: CGSize( HL_APP_WIDTH - 30 , height: CGFloat.greatestFiniteMagnitude), options: NSStringDrawingOptions.usesLineFragmentOrigin, attributes: attrButes, context: nil)
 7         
 8 //        detailHeaderView.contTextLab.text = ""
 9         detailHeaderView.contTextLab.attributedText = NSAttributedString(string: model.content!, attributes: attrButes)
10         detailHeaderView.contTextLab.numberOfLines = 0
11         detailHeaderView.contTextLab.sizeToFit()
12         context_H = size.height 
原文地址:https://www.cnblogs.com/-yun/p/10821419.html