Skip to content

Instantly share code, notes, and snippets.

@liyong03
Created March 24, 2014 05:13
Show Gist options
  • Save liyong03/9734479 to your computer and use it in GitHub Desktop.
Save liyong03/9734479 to your computer and use it in GitHub Desktop.
UILabel With Insects
static const int kUnknownTextColor = 0x666663;
static const CGFloat kUnknownFontSize = 14;
static const CGFloat kUnknownLabelMargin = 20;
@interface SocialUnknownLabel : UILabel
+ (CGFloat)requiredHeightWith:(CGFloat)width;
@end
@implementation SocialUnknownLabel
+ (CGFloat) requiredHeightWith:(CGFloat)width
{
width -= 2*kUnknownLabelMargin;
CGSize size = [UNKNOWN_TXT sizeWithFont:HelNeueFontOfSize(kUnknownFontSize)
constrainedToSize:CGSizeMake(width, 9999)
lineBreakMode:NSLineBreakByWordWrapping];
return ceilf(size.height) + 2*kUnknownLabelMargin;
}
- (id) init
{
self = [super init];
if (self) {
[self setup];
}
return self;
}
- (id) initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self setup];
}
return self;
}
- (void) setup
{
self.lineBreakMode = NSLineBreakByWordWrapping;
self.numberOfLines = 0;
self.textColor = UIColorFromRGB(kUnknownTextColor);
self.font = HelNeueFontOfSize(kUnknownFontSize);
self.text = UNKNOWN_TXT;
}
- (void) drawTextInRect:(CGRect)rect {
UIEdgeInsets insets = {kUnknownLabelMargin, kUnknownLabelMargin, kUnknownLabelMargin, kUnknownLabelMargin};
[super drawTextInRect:UIEdgeInsetsInsetRect(rect, insets)];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment