SingleConstraint.swift 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. //
  2. // ViewConstraint.swift
  3. // ExpressiveLayout
  4. //
  5. // Created by Jonas Budelmann on 5/06/14.
  6. // Copyright (c) 2014 Jonas Budelmann. All rights reserved.
  7. //
  8. import UIKit
  9. class SingleConstraint : Constraint {
  10. var firstViewAttribute: ViewAttribute
  11. var secondViewAttribute: ViewAttribute?
  12. var layoutConstant: Double = 0
  13. init(view: UIView, attribute: ViewLayoutAttribute) {
  14. firstViewAttribute = ViewAttribute(view: view, attribute: attribute)
  15. }
  16. func add(other: Any) -> Constraint {
  17. switch other {
  18. case let offset as Double:
  19. layoutConstant += offset;
  20. case let constraint as SingleConstraint:
  21. println("TODO add to \(constraint)")
  22. default:
  23. println("unsupported value: \(other)")
  24. }
  25. return self;
  26. }
  27. func equalTo(other: Any) -> Constraint {
  28. switch other {
  29. case let offset as Double:
  30. layoutConstant = offset;
  31. case let constraint as SingleConstraint:
  32. self.secondViewAttribute = constraint.firstViewAttribute;
  33. default:
  34. println("unsupported value: \(other)")
  35. }
  36. return self;
  37. }
  38. }