Skip to content

Instantly share code, notes, and snippets.

@saiday
Created March 27, 2015 05:32
Show Gist options
  • Save saiday/8e0e7f2ee9a2ab4ca8a0 to your computer and use it in GitHub Desktop.
Save saiday/8e0e7f2ee9a2ab4ca8a0 to your computer and use it in GitHub Desktop.
Self calculate height label
- (void)layoutSubviews
{
[super layoutSubviews];
if (self.numberOfLines == 0 && self.preferredMaxLayoutWidth != CGRectGetWidth(self.frame)) {
self.preferredMaxLayoutWidth = self.frame.size.width;
[self setNeedsUpdateConstraints];
}
}
- (CGSize)intrinsicContentSize
{
CGSize s = [super intrinsicContentSize];
if (self.numberOfLines == 0) {
// found out that sometimes intrinsicContentSize is 1pt too short!
s.height += 1;
}
return s;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment