Guest User

Untitled

a guest
Nov 16th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. public class ZeroConstraint: NSLayoutConstraint {
  2.  
  3. public override var constant: CGFloat {
  4. get {
  5. let adjustedConstraint = super.constant * SizeAdjustment.percentage
  6. return adjustedConstraint
  7. }
  8. set { super.constant = newValue }
  9. }
  10. }
  11.  
  12. struct SizeAdjustment {
  13.  
  14. // The percentage each element should scale by
  15. static var percentage: CGFloat = {
  16. // We design everything at this width (iPhone X). Scale up or down in
  17. // relation to it.
  18. let baseWidth: CGFloat = 375.0
  19. let percentage = UIScreen.main.bounds.width / baseWidth
  20. return percentage
  21. }()
  22. }
Add Comment
Please, Sign In to add comment