Last active
December 17, 2015 18:09
-
-
Save rbaulin/5651079 to your computer and use it in GitHub Desktop.
Label with multiple lines, constrained to width. Use with -sizeToFit.
This file contains hidden or 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
@interface MultilineLabel : UILabel | |
@property (nonatomic) CGFloat maximumWidth; | |
@end | |
@implementation MultilineLabel | |
- (id)initWithFrame:(CGRect)frame | |
{ | |
self = [super initWithFrame:frame]; | |
if (self) { | |
_maximumWidth = 200; | |
} | |
return self; | |
} | |
- (CGSize)sizeThatFits:(CGSize)size { | |
CGSize sz = [self.text sizeWithFont:self.font constrainedToSize:CGSizeMake(_maximumWidth, 999)]; | |
return sz; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment