`

swift -> UILable 计算高度, 行间距

 
阅读更多

 

UILabel 计算 高度,行间距

 

let str:String = "斯蒂芬斯蒂芬斯蒂芬斯蒂芬";

var attrButes:[NSAttributedStringKey : Any]! = nil;
let paraph = NSMutableParagraphStyle()
paraph.lineSpacing = 20
attrButes = [NSAttributedStringKey.font:UIFont.systemFont(ofSize: 13.5),NSAttributedStringKey.paragraphStyle:paraph]

let size:CGRect = str.boundingRect(with: CGSize(width: 200, height: CGFloat.greatestFiniteMagnitude), options: NSStringDrawingOptions.usesLineFragmentOrigin, attributes: attrButes, context: nil)

content.attributedText = NSAttributedString(string: str, attributes: attrButes)
content.numberOfLines = 0
content.sizeToFit()

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics