Skip to content

Instantly share code, notes, and snippets.

@joshuawright11
Created November 16, 2018 17:22
Show Gist options
  • Save joshuawright11/e7e33b13941aae14fc8fd1a6bfe7a6a4 to your computer and use it in GitHub Desktop.
Save joshuawright11/e7e33b13941aae14fc8fd1a6bfe7a6a4 to your computer and use it in GitHub Desktop.
public class ZeroConstraint: NSLayoutConstraint {
public override var constant: CGFloat {
get {
let adjustedConstraint = super.constant * SizeAdjustment.percentage
return adjustedConstraint
}
set { super.constant = newValue }
}
}
struct SizeAdjustment {
// The percentage each element should scale by
static var percentage: CGFloat = {
// We design everything at this width (iPhone X). Scale up or down in
// relation to it.
let baseWidth: CGFloat = 375.0
let percentage = UIScreen.main.bounds.width / baseWidth
return percentage
}()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment