Skip to content

Instantly share code, notes, and snippets.

@sssbohdan
Created May 26, 2017 10:23
Show Gist options
  • Save sssbohdan/35e44862fd12be94ddcdfc7f4488c392 to your computer and use it in GitHub Desktop.
Save sssbohdan/35e44862fd12be94ddcdfc7f4488c392 to your computer and use it in GitHub Desktop.
AspectFill
static func getAspectFillMultiplier(originalSize: CGSize, desirableSize: CGSize) -> CGFloat {
let heightDiff = desirableSize.height - originalSize.height
let widthDiff = desirableSize.width - originalSize.width
var multiplier: CGFloat!
if abs(heightDiff) > abs(widthDiff) {
multiplier = 1 + heightDiff / originalSize.height
} else {
multiplier = 1 + widthDiff / originalSize.width
}
return multiplier
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment