Skip to content

Instantly share code, notes, and snippets.

@shaps80
Created September 25, 2013 10:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shaps80/6697830 to your computer and use it in GitHub Desktop.
Save shaps80/6697830 to your computer and use it in GitHub Desktop.
CGRectDivide with Padding
void CGRectDivideWithPadding(CGRect rect, CGRect *slide, CGRect *remainder, CGFloat amount, CGFloat padding, CGRectEdge edge)
{
CGRect rect1, rect2;
CGRectDivide(rect, &rect1, &rect2, amount, edge);
if (edge == CGRectMaxXEdge || edge == CGRectMaxYEdge)
{
CGRect tmp = rect1;
rect1 = rect2;
rect2 = tmp;
}
(edge == CGRectMaxXEdge || edge == CGRectMinXEdge) ? (rect1.size.width -= padding / 2) : (rect1.size.height -= padding / 2);
(edge == CGRectMaxXEdge || edge == CGRectMinXEdge) ? (rect2.origin.x += padding / 2) : (rect2.origin.y += padding / 2);
(edge == CGRectMaxXEdge || edge == CGRectMinXEdge) ? (rect2.size.width -= padding / 2) : (rect2.size.height -= padding / 2);
*slide = rect1;
*remainder = rect2;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment