UIView category for determining origin and size directly

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?

+4
source share
1 answer

I find several shortcuts for setting the frame defined in three20 , really convenient for positioning and resizing views, for example:

 // frame.origin.x x // frame.origin.y y //frame.origin origin // center center // frame.size size // center.x centerX // center.y centerY // frame.size.width width // frame.size.height height // x left // x + width right // y top // y + height bottom 

All have determinants and getters.

+7
source

Source: https://habr.com/ru/post/1337930/


All Articles