Skip to content

Instantly share code, notes, and snippets.

@rodericj
Created March 28, 2014 21:21
Show Gist options
  • Save rodericj/9843244 to your computer and use it in GitHub Desktop.
Save rodericj/9843244 to your computer and use it in GitHub Desktop.
UIView *wrapper = [UIView autoLayoutView];
[wrapper constrainToWidth:300];
self.textSubtextPairs = @[@{@"label": @"abcde",
@"detail": @"Bacon ipsum dolor sit amet sausage shank ball tip jowl shoulder spare ribs prosciutto leberkas sirloin pork cow bacon beef. Bacon drumstick tongue shank. Pancetta ribeye doner andouille tri-tip sirloin t-bone tenderloin sausage bacon. Ball tip salami pig frankfurter bacon meatloaf turkey ribeye boudin t-bone corned beef short ribs short loin tongue tenderloin. Meatball turducken swine kielbasa rump prosciutto doner, short ribs boudin shankle jowl shank pig short loin. Prosciutto drumstick pork belly shank meatball. Jowl frankfurter swine, spare ribs landjaeger strip steak flank t-bone ribeye ground round meatball kevin boudin leberkas.",
@"color" : [UIColor redColor]},
@{@"label": @"cdef",
@"detail":@" t-bone tenderloin sausage bacon. Ball tip salami pig frankfurter bacon meatloaf turkey ribeye boudin t-bone corned beef short ribs short loin tongue tenderloin. Meatball turducken swine kielbasa rump prosciutto" ,
@"color" : [UIColor blueColor]},
@{@"label": @"xyz",
@"detail": @"rkey ribeye boudin t-bone corned beef short ribs short loin tongue tenderloin. Meatball turducken swine kielbasa rump prosciutto doner, short ribs boudin shankle jowl shank pig short loin. Prosciutto drumst",
@"color" : [UIColor yellowColor]}];
NSMutableArray *labels = [NSMutableArray array];
UILabel *previousLabel;
for(NSDictionary *pair in self.textSubtextPairs) {
// Header label
UILabel *label = [UILabel autoLayoutView];
label.backgroundColor = pair[@"color"];
[wrapper addSubview:label];
label.text = pair[@"label"];
[labels addObject:label];
[label constrainToHeight:16];
UILabel *detailLabel = [UILabel autoLayoutView];
[wrapper addSubview:detailLabel];
detailLabel.text = pair[@"detail"];
[detailLabel pinEdge:NSLayoutAttributeTop toEdge:NSLayoutAttributeBottom ofItem:label inset:5];
detailLabel.translatesAutoresizingMaskIntoConstraints = NO;
detailLabel.numberOfLines = 0;
[labels addObject:detailLabel];
if (previousLabel) {
[label pinEdge:NSLayoutAttributeTop toEdge:NSLayoutAttributeBottom ofItem:previousLabel inset:8];
} else {
[label pinEdge:NSLayoutAttributeTop toEdge:NSLayoutAttributeTop ofItem:wrapper];
}
previousLabel = detailLabel;
}
// add the width constraint to all of the sub views
[labels enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
[obj pinToSuperviewEdges:JRTViewPinLeftEdge|JRTViewPinRightEdge inset:10];
}];
[self.contentView addSubview:wrapper];
[wrapper pinToSuperviewEdges:JRTViewPinTopEdge inset:0];
[wrapper pinToSuperviewEdges:JRTViewPinLeftEdge inset:0];
NSLog(@"constraints is %@", wrapper);
[self setNeedsLayout];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment