//计算文字大小 class func getTextRectSize(text: NSString,font: UIFont,size: CGSize) -> CGRect { let attributes = [NSFontAttributeName: font] let option = NSStringDrawingOptions.usesLineFragmentOrigin let rect:CGRect = text.boundingRect(with: size,options: option,attributes: attributes,context: nil) return rect; } }原文链接:https://www.f2er.com/swift/322615.html