I am starting to program applications for the iPhone.
I really don’t like the way we should set the origin and size, for example:
UIView *view; CGRect frame = view.frame; frame.origin.x = 100; view.frame = frame;
or
UIView *view; view.frame = CGRectMake(100, view.frame.origin.y, view.frame.size.width, view.frame.size.height);
so I created a category for UIView:
@interface UIView (Origin) -(void) setOriginX:(CGFloat)x; -(void) setOriginY:(CGFloat)y; -(void) setOriginX:(CGFloat)xy:(CGFloat)y; -(void) setWidth:(CGFloat)w; -(void) setHeight:(CGFloat)h; -(void) setWidth:(CGFloat)w height:(CGFloat)h; @end @implementation UIView(Origin) -(void) setOriginX:(CGFloat)x { self.frame = CGRectMake(x, self.frame.origin.y, self.frame.size.width, self.frame.size.height); } ... @end
then I could write:
UIView *view; [view setOriginX 100];
this is very convenient for me, but is there any problem that I should not do such a thing or some simpler way to set the source / sizes directly?
source share