CGRectDivide is handy for slicing up a rectangle.
Example of getting a slice and the remaining area of a rectange.
CGRect rect = CGRectMake(0, 0, 240, 150);
CGRect remainder, slice;
CGRectDivide(rect, &slice, &remainder, 120, CGRectMinYEdge);
Here's a visual reference:
(0,0) (240,0)
*---------------------------------------*
| |
| |
| Slice Rectangle |
| |
| |
| |
-------------------------------------------
| |
| Remainder Rectangle |
| |
*---------------------------------------*
(0,150) (240,150)
(diagram via http://soulwithmobiletechnology.blogspot.com/2011/08/how-to-divide-cgrect-using-cgrectdivide.html)
Divides a source rectangle into two component rectangles.
void CGRectDivide (
CGRect rect,
CGRect *slice,
CGRect *remainder,
CGFloat amount,
CGRectEdge edge
);
The source rectangle.
On input, a pointer to an uninitialized rectangle. On return, the rectangle is filled in with the specified edge and values that extends the distance beyond the edge specified by the amount parameter.
On input, a pointer to an uninitialized rectangle. On return, the rectangle contains the portion of the source rectangle that remains after CGRectEdge produces the “slice” rectangle.
A distance from the rectangle side that is specified in the edge parameter. This distance defines the line, parallel to the specified side, that Quartz uses to divide the source rectangle.
An edge value that specifies the side of the rectangle from which the distance passed in the amount parameter is measured. CGRectDivide produces a “slice” rectangle that contains the specified edge and extends amount distance beyond it.
Available in iOS 2.0 and later.
CGGeometry.h