前端之家收集整理的这篇文章主要介绍了
swift中计算字符串的宽高,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
// 计算字符串的宽度,高度
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)
原文链接:https://www.f2er.com/swift/322941.html