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 阅读(858) 评论(0) 编辑 收藏 举报
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步