Last active
December 14, 2015 20:19
-
-
Save Tricertops/5142819 to your computer and use it in GitHub Desktop.
Adjusting frame of UIView. The easier way.
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
// UIView category | |
- (void)adjustFrame:(void(^)(CGRect *frame))block { | |
CGRect frame = self.frame; | |
block(&frame); | |
self.frame = frame; | |
} |
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
// Usage: | |
[view adjustFrame:^(CGRect *frame) { | |
frame->origin.x = 10; | |
frame->size = someSize; | |
}]; | |
// + You never forget to re-assign the frame. | |
// + You don't need to create local variable. | |
// + The block argument is autocompleted and has its own scope. | |
// - You work with pointer to struct so use arrow `->` instead of dot. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment