Skip to content

Instantly share code, notes, and snippets.

@twobitlabs
Created March 8, 2013 23:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save twobitlabs/5121054 to your computer and use it in GitHub Desktop.
Save twobitlabs/5121054 to your computer and use it in GitHub Desktop.
Sample UIKit layout code
-(void)contentUpdated {
CGFloat outsidePadding = 10;
CGFloat paddingBetweenElements = 5;
CGFloat maxHeadlineHeight = 200;
self.thumbnail.frame = (CGRect){(CGPoint){outsidePadding, outsidePadding}, self.thumbnail.image.size};
CGFloat headlineWidth = WIDTH(self) - (RIGHT(self.thumbnail) + paddingBetweenElements + outsidePadding);
CGFloat headlineHeight = [self.headline.text sizeWithFont:self.headline.font
constrainedToSize:CGSizeMake(headlineWidth, maxHeadlineHeight)].height;
self.headline.frame = CGRectMake(RIGHT(self.thumbnail) + paddingBetweenElements, TOP(self.thumbnail), headlineWidth, headlineHeight);
CGFloat bylineWidth = [self.byline.text sizeWithFont:self.byline.font].width;
CGFloat bylineHeight = self.byline.font.lineHeight;
self.byline.frame = CGRectMake(LEFT(self.headline), BOTTOM(self.headline) + paddingBetweenElements, bylineWidth, bylineHeight);
CGFloat dateWidth = [self.date.text sizeWithFont:self.date.font].width;
self.date.frame = CGRectMake(RIGHT(self.byline) + paddingBetweenElements, TOP(self.byline), dateWidth, bylineHeight);
CGFloat bottom = CGFloat bottom = fmaxf(BOTTOM(self.thumbnail), BOTTOM(self.byline));
// find this and other useful UIView categories at https://github.com/twobitlabs/TBLCategories
[self setHeight:bottom + outsidePadding];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment