Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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