//计算文字大小 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; } }