Swift tableViewCell 高度自适应

2016-06-23  本文已影响887人  刘宇航iOS
 static func cellhight (content: String) -> CGFloat {

        let rect: CGRect = content.boundingRectWithSize(
            CGSizeMake(SCREENWIDTH - 20, 0),
            options: NSStringDrawingOptions.UsesLineFragmentOrigin,
            attributes: [NSFontAttributeName:
            UIFont.systemFontOfSize(14)],
            context: nil)
    
        return rect.height + 61
    }

在返回cell 的高度的方法中直接调用
return TableViewCell.cellhight("这里面填想要自适应的文字")

上一篇 下一篇

猜你喜欢

热点阅读