Created
March 8, 2013 23:38
-
-
Save twobitlabs/5121054 to your computer and use it in GitHub Desktop.
Sample UIKit layout code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(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