swift 计算label高度与长度

前端之家收集整理的这篇文章主要介绍了swift 计算label高度与长度前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

func getLabHeigh(labelStr:String,font:UIFont,width:CGFloat) -> CGFloat {

let statusLabelText: NSString = labelStr

let size = CGSizeMake(width,900)

let dic = NSDictionary(object: font,forKey: NSFontAttributeName)

let strSize = statusLabelText.boundingRectWithSize(size,options: .UsesLineFragmentOrigin,attributes: dic as? [String : AnyObject],context: nil).size

return strSize.height

}

func getLabWidth(labelStr:String,height:CGFloat) -> CGFloat {

let statusLabelText: NSString = labelStr

let size = CGSizeMake(900,height)

let dic = NSDictionary(object: font,context: nil).size

return strSize.width

}

原文链接:https://www.f2er.com/swift/323521.html

猜你在找的Swift相关文章