直接上代码,如下:
/**
@H_403_6@ * 获取字符串的宽度和高度*
* @param text:NSString
* @param font:UIFont
*
* @return CGRect
*/
class func getTextRectSize(text:NSString,font:UIFont,size:CGSize) -> CGRect {
var attributes = [NSFontAttributeName: font]
var option = NSStringDrawingOptions.UsesLineFragmentOrigin
var rect:CGRect = text.boundingRectWithSize(size,options: option,attributes: attributes,context: nil)
// println("rect:\(rect)");
return rect;
}
原文链接:https://www.f2er.com/swift/326231.html