Created
July 31, 2015 07:51
CGSizeAspectFit & CGSizeAspectFill from http://stackoverflow.com/a/17948778
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
CGSize CGSizeAspectFit(CGSize aspectRatio, CGSize boundingSize) | |
{ | |
float mW = boundingSize.width / aspectRatio.width; | |
float mH = boundingSize.height / aspectRatio.height; | |
if( mH < mW ) | |
boundingSize.width = boundingSize.height / aspectRatio.height * aspectRatio.width; | |
else if( mW < mH ) | |
boundingSize.height = boundingSize.width / aspectRatio.width * aspectRatio.height; | |
return boundingSize; | |
} | |
CGSize CGSizeAspectFill(CGSize aspectRatio, CGSize minimumSize) | |
{ | |
float mW = minimumSize.width / aspectRatio.width; | |
float mH = minimumSize.height / aspectRatio.height; | |
if( mH > mW ) | |
minimumSize.width = minimumSize.height / aspectRatio.height * aspectRatio.width; | |
else if( mW > mH ) | |
minimumSize.height = minimumSize.width / aspectRatio.width * aspectRatio.height; | |
return minimumSize; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment