Last active
May 16, 2020 02:51
-
-
Save jverkoey/5288470 to your computer and use it in GitHub Desktop.
Layout + size calculations for iOS.
This file contains hidden or 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
- (CGSize)sizeOfContentsWithSize:(CGSize)size | |
shouldLayout:(BOOL)shouldLayout { | |
// Calculate frames. | |
if (shouldLayout) { | |
// Update frames. | |
} | |
return // size | |
} | |
- (CGSize)sizeThatFits:(CGSize)size { | |
return [self sizeOfContentsWithSize:size shouldLayout:NO]; | |
} | |
- (void)layoutSubviews { | |
[super layoutSubviews]; | |
[self sizeOfContentsWithSize:self.bounds.size shouldLayout:YES]; | |
} |
@taylanpince because sizeThatFits is a question that may be asked multiple times before the eventual layout of the view occurs. Calling sizeThatFits shouldn't affect the frame of the view.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why not call:
And do the calculation in
sizeThatFits: