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

swift - 动态计算文本高度

时间:2015-12-08 08:44:56      阅读:428      评论:0      收藏:0      [点我收藏+]

标签:

    func heightOfCell(text : String) -> CGFloat {
        let attributes = [NSFontAttributeName:UIFont.systemFontOfSize(14)]
        let option = NSStringDrawingOptions.UsesLineFragmentOrigin
        let rect:CGRect = text.boundingRectWithSize(CGSize(width: self.frame.size.width - 20, height: 0), options: option, attributes: attributes, context: nil)
        print("height is \(rect.size.height)")
        return rect.size.height + 50
    }

swift - 动态计算文本高度

标签:

原文地址:http://www.cnblogs.com/tian-sun/p/5028042.html

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