Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
计算UILabel的高度
/*//创建一个UILabel
var articleLabel:UILabel = UILabel(frame: CGRectMake(20.0, 100.0, self.view.frame.width - 40.0, 0.0));
//设置AttributedText
var attributeString:NSMutableAttributedString = NSMutableAttributedString(string: self.article!);
var style:NSMutableParagraphStyle = NSMutableParagraphStyle();
style.lineSpacing = 5.0;
attributeString.addAttribute(NSParagraphStyleAttributeName, value: style, range: NSMakeRange(0, attributeString.length));
articleLabel.attributedText = attributeString;
articleLabel.numberOfLines = 0;
articleLabel.font = UIFont.systemFontOfSize(14.0);
articleLabel.textColor = UIColor(red: 0.576, green: 0.573, blue: 0.576, alpha: 1.0);
//需要自动生成Label的高度
var expectedLabelSize = articleLabel.attributedText.boundingRectWithSize(CGSizeMake(self.view.frame.width, 999), options: NSStringDrawingOptions.UsesLineFragmentOrigin, context: nil);
articleLabel.frame.size.height = expectedLabelSize.size.height;
self.view.addSubview(articleLabel);*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.