I am a beginner of iPhone app programing.
I really don’t like the way we have to set origins and sizes like:
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 like:
@interface UIView (Origin)
-(void) setOriginX:(CGFloat)x;
-(void) setOriginY:(CGFloat)y;
-(void) setOriginX:(CGFloat)x y:(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 much convenient for me, but is there any concern that i shouldn’t do such thing, or any easier way to set origins/sizes directly?
I find a few shortcuts for setting frame defined in three20 really convenient for positioning and resizing views, like:
They all have setters and getters defined.