Skip to content

Instantly share code, notes, and snippets.

@ShadoFlameX
Created February 19, 2013 08:38
Show Gist options
  • Save ShadoFlameX/4984083 to your computer and use it in GitHub Desktop.
Save ShadoFlameX/4984083 to your computer and use it in GitHub Desktop.
When doing iOS view layouts I end up needing to center CGRects within a CGRect while maintaining on pixel origin and size. This will do just that.
CG_INLINE CGRect CGRectIntegralCenteredInRect(CGRect innerRect, CGRect outerRect)
{
CGFloat originX = floorf((outerRect.size.width - innerRect.size.width) * 0.5f);
CGFloat originY = floorf((outerRect.size.height - innerRect.size.height) * 0.5f);
return CGRectMake(originX, originY, innerRect.size.width, innerRect.size.height);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment