Created
March 15, 2012 00:33
-
-
Save nielsbot/2040713 to your computer and use it in GitHub Desktop.
Pixel align your UIViews even when using the center property
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
@implementation UIView (PositionAtCenter) | |
-(void)centerPixelAligned:(CGPoint)p | |
{ | |
CGSize size = self.bounds.size ; | |
p.x = floorf( p.x ) + 0.5 * fmodf( size.width, 2.0f ) ; | |
p.y = floorf( p.y ) + 0.5 * fmodf( size.height, 2.0f ) ; | |
self.center = p; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment