Search code examples
iosobjective-ccocoa-touchuiviewcgrectmake

Modifying UIView frame more easily?


Often I need to simply move the view 5 pixels down. My approach is like this

view.frame = CGRectMake(view.frame.origin.x,
                        view.frame.origin.y + 5,
                        view.frame.size.width,
                        view.frame.size.height);

Isn't there some easier way? :-/


Solution

  • Perhaps I should write a bunch of categories for the UIView class.

    Something like

    -(void)changeFrameOriginHorizontally:(NSInteger)paramHorizontalChange
                              vertically:(NSInteger)paramVerticalChange;
    
    -(void)changeFrameSizeHorizontally:(NSInteger)paramHorizontalChange
                            vertically:(NSinteger)paramVerticalChange;
    

    The main reason I do not like the solution in my original post is that it is very code sense unfriendly and too verbose.

    I would allow for negative and positive values and nil for no change.

    What do you guys think?