/**
- 计算宽度 内容 字体大小
*/
func labelWidth(_ text: String, _ height: CGFloat) -> CGFloat {
let size = CGSize(width: 2000, height: height)
let font = UIFont(name: "PingFang-SC-Regular", size: height)!
let attributes = [NSAttributedStringKey.font: font]
let labelSize = NSString(string: text).boundingRect(with: size, options: .usesLineFragmentOrigin, attributes: attributes, context: nil)
return labelSize.width
}
网友评论