Operators.swift 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //
  2. // Operators.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. //TODO spilt into different files
  10. enum ViewLayoutAttribute {
  11. case CenterX
  12. case CenterY
  13. case Left
  14. case Right
  15. case Top
  16. case Bottom
  17. case Width
  18. case Height
  19. }
  20. class ViewAttribute {
  21. weak var view: UIView?
  22. let attribute: ViewLayoutAttribute
  23. init(view: UIView, attribute: ViewLayoutAttribute) {
  24. self.view = view
  25. self.attribute = attribute
  26. }
  27. }
  28. @infix func + (left: Constraint, right: Any) -> Constraint {
  29. return left.add(right);
  30. }
  31. @infix func == (left: Constraint, right: Any) -> Constraint {
  32. return left.equalTo(right);
  33. }
  34. func installConstraints(constraints: Array<Constraint>) {
  35. // find common superview
  36. // create NSLayoutConstraint
  37. }
  38. extension UIView {
  39. var left: Constraint { return SingleConstraint(view: self, attribute: .Left) }
  40. var right: Constraint { return SingleConstraint(view: self, attribute: .Right) }
  41. var top: Constraint { return SingleConstraint(view: self, attribute: .Top) }
  42. var bottom: Constraint { return SingleConstraint(view: self, attribute: .Bottom) }
  43. }