Skip to content

Instantly share code, notes, and snippets.

@rbaulin
Last active December 17, 2015 18:09
Show Gist options
  • Save rbaulin/5651079 to your computer and use it in GitHub Desktop.
Save rbaulin/5651079 to your computer and use it in GitHub Desktop.
Label with multiple lines, constrained to width. Use with -sizeToFit.
@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