Skip to content

Instantly share code, notes, and snippets.

@mpospese
Created February 28, 2013 03:34
Show Gist options
  • Star 70 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save mpospese/5053969 to your computer and use it in GitHub Desktop.
Save mpospese/5053969 to your computer and use it in GitHub Desktop.
Pixel aligns rectangles, taking the device's screen scale into account.
CGRect CGRectIntegralScaledEx(CGRect rect, CGFloat scale)
{
return CGRectMake(floorf(rect.origin.x * scale) / scale, floorf(rect.origin.y * scale) / scale, ceilf(rect.size.width * scale) / scale, ceilf(rect.size.height * scale) / scale);
}
CGRect CGRectIntegralScaled(CGRect rect)
{
return CGRectIntegralScaledEx(rect, [[UIScreen mainScreen] scale]);
}
CGRect CGRectIntegralMake(CGFloat x, CGFloat y, CGFloat width, CGFloat height)
{
return CGRectIntegralScaledEx(CGRectMake(x, y, width, height), [[UIScreen mainScreen] scale]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment