// 计算字符串的宽度,高度 let string:String = "swift中计算字符串的宽度和高度。swift中计算字符串的宽度和高度。swift中计算字符串的宽度和高度。" let font:UIFont! = UIFont(name: "EuphemiaUCAS",size: 12.0) let attributes = [NSFontAttributeName:font] let option = NSStringDrawingOptions.UsesLineFragmentOrigin let rect:CGRect = string.boundingRectWithSize(CGSizeMake(320.0,999.9),options: option,attributes: attributes,context: nil) print("rect:\(rect)")
rect:(0.0,0.0,313.078125,31.67578125)