Skip to content

Instantly share code, notes, and snippets.

@jcromartie
Last active December 16, 2015 10:38
Show Gist options
  • Save jcromartie/5421145 to your computer and use it in GitHub Desktop.
Save jcromartie/5421145 to your computer and use it in GitHub Desktop.
- (id)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
[titleLabel setTranslatesAutoresizingMaskIntoConstraints:NO];
[titleLabel setNumberOfLines:0];
[titleLabel setLineBreakMode:NSLineBreakByWordWrapping];
[self addSubview:titleLabel];
UILabel *dateLabel = [[UILabel alloc] initWithFrame:CGRectZero];
[dateLabel setTranslatesAutoresizingMaskIntoConstraints:NO];
[dateLabel setNumberOfLines:0];
[titleLabel setLineBreakMode:NSLineBreakByWordWrapping];
[self addSubview:dateLabel];
UILabel *summaryLabel = [[UILabel alloc] initWithFrame:CGRectZero];
[summaryLabel setTranslatesAutoresizingMaskIntoConstraints:NO];
[summaryLabel setNumberOfLines:0];
[summaryLabel setLineBreakMode:NSLineBreakByTruncatingTail];
[self addSubview:summaryLabel];
NSDictionary *views = NSDictionaryOfVariableBindings(titleLabel, summaryLabel, dateLabel);
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|-[titleLabel]-|" options:0 metrics:nil views:views]];
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|-[dateLabel]-|" options:0 metrics:nil views:views]];
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|-[summaryLabel]-|" options:0 metrics:nil views:views]];
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[titleLabel][dateLabel]-2-[summaryLabel]-|" options:0 metrics:nil views:views]];
NSLayoutConstraint *summaryLabelBottomSpace = [NSLayoutConstraint constraintWithItem:summaryLabel attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationLessThanOrEqual toItem:self attribute:NSLayoutAttributeBottom multiplier:1.0 constant:-8.0];
[self addConstraint:summaryLabelBottomSpace];
}
return self;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment