Created
December 12, 2012 04:23
-
-
Save jspahrsummers/4264845 to your computer and use it in GitHub Desktop.
An example of clean CGRectDivide-based layout.
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)resizeSubviewsWithOldSize:(CGSize)oldSize { | |
[super resizeSubviewsWithOldSize:oldSize]; | |
CGRect availableRect = CGRectInset(self.bounds, GHGitSetupViewHorizontalMargin, GHGitSetupViewVerticalMargin); | |
CGFloat labelWidth = fmax(CGRectGetWidth(self.nameLabel.bounds), CGRectGetWidth(self.emailLabel.bounds)); | |
CGRect nameRect = CGRectZero; | |
CGRectDivideWithPadding(availableRect, &nameRect, &availableRect, CGRectGetHeight(self.nameTextField.bounds), GHGitSetupViewControlVerticalPadding, CGRectMaxYEdge); | |
CGRectDivideWithPadding(nameRect, self.nameLabel.frame, self.nameTextField.frame, labelWidth, GHGitSetupViewControlHorizontalPadding, CGRectMinXEdge); | |
CGRect emailRect = CGRectZero; | |
CGRectDivideWithPadding(availableRect, &emailRect, &availableRect, CGRectGetHeight(self.emailTextField.bounds), GHGitSetupViewControlVerticalPadding, CGRectMaxYEdge); | |
CGRectDivideWithPadding(emailRect, self.emailLabel.frame, self.emailTextField.frame, labelWidth, GHGitSetupViewControlHorizontalPadding, CGRectMinXEdge); | |
CGRectDivideWithPadding(availableRect, NULL, self.explanatoryLabel.frame, labelWidth, GHGitSetupViewControlHorizontalPadding, CGRectMinXEdge); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Half the length of the equivalent Auto Layout code, easier to understand (once you grok the one main function being used), and easier to debug if it's wrong.