计算label
Posted 世界仔
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了计算label相关的知识,希望对你有一定的参考价值。
func getCGSize(size:CGSize,fontSize:CGFloat,text:String)->CGSize{
let attributes = [NSFontAttributeName:UIFont.systemFontOfSize(fontSize)]
let option = NSStringDrawingOptions.UsesLineFragmentOrigin
let sizeMake = text.boundingRectWithSize(size, options: option, attributes: attributes, context: nil).size
return sizeMake
}
func labelSize(x:CGFloat,y:CGFloat,text:String,attribute :AnyObject) -> CGRect{
var size = CGRect(origin: CGPoint(x:x,y:y), size: CGSize(width: SCREEN_WIDTH, height: SCREEN_HEIGHT))
var size2 = CGSize(width: SCREEN_WIDTH, height: 10000);//设置label的最大宽度
size = text.boundingRectWithSize(size2, options: NSStringDrawingOptions.UsesLineFragmentOrigin, attributes: attribute as! [String : AnyObject] , context: nil)
return size
}
以上是关于计算label的主要内容,如果未能解决你的问题,请参考以下文章