Skip to content

Instantly share code, notes, and snippets.

@Tricertops
Last active December 14, 2015 20:19
Show Gist options
  • Save Tricertops/5142819 to your computer and use it in GitHub Desktop.
Save Tricertops/5142819 to your computer and use it in GitHub Desktop.
Adjusting frame of UIView. The easier way.
// UIView category
- (void)adjustFrame:(void(^)(CGRect *frame))block {
CGRect frame = self.frame;
block(&frame);
self.frame = frame;
}
// 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