Created
February 18, 2013 11:45
-
-
Save usirin/4976803 to your computer and use it in GitHub Desktop.
Centering a frame into screen.
This file contains hidden or 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
| // 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