Skip to content

Instantly share code, notes, and snippets.

@JaleelNazir
Forked from saiday/UILabelSubClass
Created February 25, 2016 11:41
Show Gist options
  • Save JaleelNazir/e23c154e533d29ba4719 to your computer and use it in GitHub Desktop.
Save JaleelNazir/e23c154e533d29ba4719 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