Skip to content

Instantly share code, notes, and snippets.

@usirin
Created February 18, 2013 11:45
Show Gist options
  • Select an option

  • Save usirin/4976803 to your computer and use it in GitHub Desktop.

Select an option

Save usirin/4976803 to your computer and use it in GitHub Desktop.
Centering a frame into screen.
// centering the images inside.
CGSize boundsSize = self.view.bounds.size;
CGRect frameToCenter = imageView.frame;
// center horizontally
if (frameToCenter.size.width < boundsSize.width)
frameToCenter.origin.x = (boundsSize.width - frameToCenter.size.width) / 2;
else
frameToCenter.origin.x = 0;
// center vertically
if (frameToCenter.size.height < boundsSize.height) {
frameToCenter.origin.y = (boundsSize.height - frameToCenter.size.height) / 2;
}
else {
frameToCenter.origin.y = 0;
}
imageView.frame = frameToCenter;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment