swift UILabel的高度自适应
Posted 妖妖yaoyao
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了swift UILabel的高度自适应相关的知识,希望对你有一定的参考价值。
let label = UILabel.init() label.backgroundColor = UIColor.grayColor() label.text = "1234567890-edfdgddffgfgfggfggddfbyfru6y6r7iuymgnjnrtfugyu57t6injyunjokn89uilmghbjl,hknjlllllllllllllllllllllllllllllllllllllmimomomkjnijunbuygbtyfrtdrxcresxweaswa" label.font = UIFont.systemFontOfSize(14 ) label.textColor = UIColor.redColor() let string:NSString = label.text! let options:NSStringDrawingOptions = .UsesLineFragmentOrigin let boundingRect = string.boundingRectWithSize(CGSizeMake(200, 0), options: options, attributes:[NSFontAttributeName:label.font], context: nil) label.frame = CGRectMake(0, 20, 200, boundingRect.height) label.numberOfLines = 0; label.lineBreakMode = NSLineBreakMode.ByWordWrapping self.view.addSubview(label)
以上是关于swift UILabel的高度自适应的主要内容,如果未能解决你的问题,请参考以下文章