Skip to content

Instantly share code, notes, and snippets.

@maninp
Forked from brynbodayle/gist:de70eb6a392e90272707
Last active August 29, 2015 14:24
Show Gist options
  • Save maninp/a50b6b34a980e13dd96a to your computer and use it in GitHub Desktop.
Save maninp/a50b6b34a980e13dd96a to your computer and use it in GitHub Desktop.
- (CGSize)intrinsicContentSize {
CGSize boundingSize = CGSizeMake(self.titleLabel.preferredMaxLayoutWidth - self.titleEdgeInsets.left - self.titleEdgeInsets.right, CGFLOAT_MAX);
NSAttributedString *attributedTitle = [self attributedTitleForState:self.state];
CGRect boundingRect;
if(attributedTitle) {
boundingRect = [attributedTitle boundingRectWithSize:boundingSize options:(NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading) context:NULL];
}
else {
NSString *title = [self titleForState:self.state];
boundingRect = [title boundingRectWithSize:boundingSize options:(NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading) attributes:@{NSFontAttributeName : self.titleLabel.font} context:NULL];
}
return CGSizeMake(boundingRect.size.width + self.titleEdgeInsets.left + self.titleEdgeInsets.right, boundingRect.size.height + self.titleEdgeInsets.top + self.titleEdgeInsets.bottom);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment