Skip to content

Instantly share code, notes, and snippets.

@nielsbot
Created March 15, 2012 00:33
Show Gist options
  • Save nielsbot/2040713 to your computer and use it in GitHub Desktop.
Save nielsbot/2040713 to your computer and use it in GitHub Desktop.
Pixel align your UIViews even when using the center property
@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