Created
November 16, 2018 17:22
-
-
Save joshuawright11/e7e33b13941aae14fc8fd1a6bfe7a6a4 to your computer and use it in GitHub Desktop.
This file contains 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
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