Created
May 19, 2014 07:42
-
-
Save WJachowicz/cada29a14b521ffaba62 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@implementation VCCMultilineLabel | |
- (id)init | |
{ | |
if ((self = [super init])) { | |
self.numberOfLines = 0; | |
self.lineBreakMode = NSLineBreakByWordWrapping; | |
} | |
return self; | |
} | |
- (void)layoutSubviews | |
{ | |
[super layoutSubviews]; | |
// Fit the label to it's contents on rotation or text change | |
// http://stackoverflow.com/questions/15927086/uilabel-sizetofit-and-constraints | |
if (self.preferredMaxLayoutWidth != [self alignmentRectForFrame:self.frame].size.width) { | |
self.preferredMaxLayoutWidth = [self alignmentRectForFrame:self.frame].size.width; | |
[self.superview setNeedsLayout]; | |
} | |
} | |
- (CGSize) intrinsicContentSize | |
{ | |
CGSize s = [super intrinsicContentSize]; | |
if ( self.numberOfLines == 0 ) | |
{ | |
// found out that sometimes intrinsicContentSize is 1pt too short! | |
s.height += 1; | |
} | |
return s; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment