swift - 动态计算文本高度
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
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
}
posted on 2015-12-08 08:12 taiyang2014 阅读(854) 评论(0) 编辑 收藏 举报