码迷,mamicode.com
首页 > 编程语言 > 详细

swift计算label动态宽度和高度

时间:2016-08-24 12:45:59      阅读:246      评论:0      收藏:0      [点我收藏+]

标签:

  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,font:UIFont,height:CGFloat) -> CGFloat {

        let statusLabelText: NSString = labelStr

        let size = CGSizeMake(900, height)

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

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

        return strSize.width

    }

swift计算label动态宽度和高度

标签:

原文地址:http://www.cnblogs.com/YangFuShun/p/5802059.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!