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.

Revisions

  1. liyong03 created this gist Mar 24, 2014.
    57 changes: 57 additions & 0 deletions gistfile1.m
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,57 @@

    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