More CGRect functions

Here are a few more functions useful in creating CGRect’s from a center point and size.

Example usage:

1
view.frame = CGRectWithCenterWidthHeight(parent.center,30,30);

Full set of functions

interface

1
2
CGRect CGRectWithCenterAndSize(CGPoint center, CGSize size);
CGRect CGRectWithCenterWidthHeight(CGPoint center, CGFloat width,CGFloat height);

implementation

1
2
3
4
5
6
7
CGRect CGRectWithCenterAndSize(CGPoint center, CGSize size){
return CGRectMake(center.x - (size.width/2), center.y - (size.height/2), size.width, size.height);
}
CGRect CGRectWithCenterWidthHeight(CGPoint center, CGFloat width,CGFloat height){
return CGRectWithCenterAndSize(center,CGSizeMake(width, height));
}