Sunday, October 11, 2009

iPhone dev Stupidity 42: use category for convenient methods

These are nice for UIView and they can be declared as properties:

@property (readonly, nonatomic) int width;


@property (readonly, nonatomic) int height;


@property (readonly, nonatomic) int x;


@property (readonly, nonatomic) int y;


@property (readonly, nonatomic) int centerX;


@property (readonly, nonatomic) int centerY;


@property (readonly, nonatomic) int right;


@property (readonly, nonatomic) int bottom;



- (int) width{


return (int) self.frame.size.width;


}




- (int) height{


return (int) self.frame.size.height;


}




- (int) x{


return (int) self.frame.origin.x;


}




- (int) y{


return (int) self.frame.origin.y;


}




- (int) centerX{


return self.center.x;


}




- (int) centerY{


return self.center.y;


}




- (int) right{


return CGRectGetMaxX(self.frame);


}




- (int) bottom{


return CGRectGetMaxY(self.frame);


}



No comments: