-
Notifications
You must be signed in to change notification settings - Fork 106
Open
Labels
Description
adding a category with convenience methods would simplify writing commonly used code to update one or more parameters of a frame, example:
// interface declaration is left to the reader as an exercise
@implementation UIView (FrameHelpers)
// this one could be called setOrigin
- (void)setX:(CGFloat)x y:(CGFloat)y {
CGRect frame = self.frame;
frame.origin = CGPointMake(x, y);
self.frame = frame;
}
@end
// usage
[someView setX:42 y:someOffset];you could also create a helper class like GeometryHelper to do the same but with any CGRect (if you have a need to operate on arbitrary rects and not just view frames) and then utilize it in the above category. In relation to this there're already some helper functions to modify CGRect: https://developer.apple.com/documentation/coregraphics/cggeometry?language=objc#Modifying-Rectangles
P.S. But with AutoLayout this is not needed :)
Reactions are currently unavailable