Skip to content

Instantly share code, notes, and snippets.

@brunojppb
Created April 20, 2017 08:55
Show Gist options
  • Save brunojppb/3603f09f5bda63d2ffb196e85213d521 to your computer and use it in GitHub Desktop.
Save brunojppb/3603f09f5bda63d2ffb196e85213d521 to your computer and use it in GitHub Desktop.
import UIKit
extension CGFloat {
/** Targeting the Photo Book API, converts pixels to points */
var pixelToPoints: CGFloat {
let pointsPerInch: CGFloat = 72
let scale: CGFloat = UIScreen.main.scale
let pixelPerInch: CGFloat
if UIDevice.current.userInterfaceIdiom == .pad {
pixelPerInch = 132 * scale
} else if UIDevice.current.userInterfaceIdiom == .phone {
pixelPerInch = 163 * scale
} else {
pixelPerInch = 160 * scale
}
return self * pointsPerInch / pixelPerInch
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment