Created
February 19, 2013 08:38
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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