Swiftcell和Label的自适应高度
发布时间:2023-11-01 11:00:55 所属栏目:教程 来源:转载
导读: 思路是这样的,获取文字,设置文字大小,设置文字行宽,设置Label的numberLines = 0,然后得到高度
,赋值给Lebel的frame
//计算文本高度
let options :
,赋值给Lebel的frame
//计算文本高度
let options :
思路是这样的,获取文字,设置文字大小,设置文字行宽,设置Label的numberLines = 0,然后得到高度 ,赋值给Lebel的frame //计算文本高度 let options : NSStringDrawingOptions = NSStringDrawingOptions.UsesLineFragmentOrigin blogDicText.font = UIFont.systemFontOfSize(17) let string:NSString = bloginfo.content! let screenBounds:CGRect = UIScreen.mainScreen().bounds let boundingRect = string.boundingRectWithSize(CGSizeMake(screenBounds.width-5, 0), options: options, attributes: [NSFontAttributeName:blogDicText.font], context: nil) blogDicText.text = bloginfo.content! blogDicText.frame = CGRectMake(5, 5, boundingRect.size.width, boundingRect.size.height) 如果你想规定高度大于多少显示多少行只需要改变Label的numberLines = ?就可以了。 cell的高度一样,文本的高度加上图片的高度就可以算出cell的高度! (编辑:好传媒网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐