Skip to content

create convenience methods to update frame #1350

@kambala-decapitator

Description

@kambala-decapitator

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 :)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions