View.swift 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //
  2. // View.swift
  3. // Snappy
  4. //
  5. // Copyright (c) 2011-2014 Masonry Team - https://github.com/Masonry
  6. //
  7. // Permission is hereby granted, free of charge, to any person obtaining a copy
  8. // of this software and associated documentation files (the "Software"), to deal
  9. // in the Software without restriction, including without limitation the rights
  10. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. // copies of the Software, and to permit persons to whom the Software is
  12. // furnished to do so, subject to the following conditions:
  13. //
  14. // The above copyright notice and this permission notice shall be included in
  15. // all copies or substantial portions of the Software.
  16. //
  17. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  23. // THE SOFTWARE.
  24. import UIKit
  25. typealias View = UIView
  26. extension View {
  27. #if SNP_SHORTHAND
  28. var left: ConstraintItem { return ConstraintItem(view: self, attributes: ConstraintAttributes.Left) }
  29. var top: ConstraintItem { return ConstraintItem(view: self, attributes: ConstraintAttributes.Top) }
  30. var right: ConstraintItem { return ConstraintItem(view: self, attributes: ConstraintAttributes.Right) }
  31. var bottom: ConstraintItem { return ConstraintItem(view: self, attributes: ConstraintAttributes.Bottom) }
  32. var leading: ConstraintItem { return ConstraintItem(view: self, attributes: ConstraintAttributes.Leading) }
  33. var trailing: ConstraintItem { return ConstraintItem(view: self, attributes: ConstraintAttributes.Trailing) }
  34. var width: ConstraintItem { return ConstraintItem(view: self, attributes: ConstraintAttributes.Width) }
  35. var height: ConstraintItem { return ConstraintItem(view: self, attributes: ConstraintAttributes.Height) }
  36. var centerX: ConstraintItem { return ConstraintItem(view: self, attributes: ConstraintAttributes.CenterX) }
  37. var centerY: ConstraintItem { return ConstraintItem(view: self, attributes: ConstraintAttributes.CenterY) }
  38. var baseline: ConstraintItem { return ConstraintItem(view: self, attributes: ConstraintAttributes.Baseline) }
  39. var edges: ConstraintItem { return ConstraintItem(view: self, attributes: ConstraintAttributes.Edges) }
  40. var size: ConstraintItem { return ConstraintItem(view: self, attributes: ConstraintAttributes.Size) }
  41. var center: ConstraintItem { return ConstraintItem(view: self, attributes: ConstraintAttributes.Center) }
  42. func makeConstraints(block: (maker: ConstraintMaker) -> ()) {
  43. ConstraintMaker.makeConstraints(self, block: block)
  44. }
  45. func remakeConstraints(block: (maker: ConstraintMaker) -> ()) {
  46. ConstraintMaker.remakeConstraints(self, block: block)
  47. }
  48. #else
  49. var snp_left: ConstraintItem { return ConstraintItem(view: self, attributes: ConstraintAttributes.Left) }
  50. var snp_top: ConstraintItem { return ConstraintItem(view: self, attributes: ConstraintAttributes.Top) }
  51. var snp_right: ConstraintItem { return ConstraintItem(view: self, attributes: ConstraintAttributes.Right) }
  52. var snp_bottom: ConstraintItem { return ConstraintItem(view: self, attributes: ConstraintAttributes.Bottom) }
  53. var snp_leading: ConstraintItem { return ConstraintItem(view: self, attributes: ConstraintAttributes.Leading) }
  54. var snp_trailing: ConstraintItem { return ConstraintItem(view: self, attributes: ConstraintAttributes.Trailing) }
  55. var snp_width: ConstraintItem { return ConstraintItem(view: self, attributes: ConstraintAttributes.Width) }
  56. var snp_height: ConstraintItem { return ConstraintItem(view: self, attributes: ConstraintAttributes.Height) }
  57. var snp_centerX: ConstraintItem { return ConstraintItem(view: self, attributes: ConstraintAttributes.CenterX) }
  58. var snp_centerY: ConstraintItem { return ConstraintItem(view: self, attributes: ConstraintAttributes.CenterY) }
  59. var snp_baseline: ConstraintItem { return ConstraintItem(view: self, attributes: ConstraintAttributes.Baseline) }
  60. var snp_edges: ConstraintItem { return ConstraintItem(view: self, attributes: ConstraintAttributes.Edges) }
  61. var snp_size: ConstraintItem { return ConstraintItem(view: self, attributes: ConstraintAttributes.Size) }
  62. var snp_center: ConstraintItem { return ConstraintItem(view: self, attributes: ConstraintAttributes.Center) }
  63. func snp_makeConstraints(block: (maker: ConstraintMaker) -> ()) {
  64. ConstraintMaker.makeConstraints(self, block: block)
  65. }
  66. func snp_remakeConstraints(block: (maker: ConstraintMaker) -> ()) {
  67. ConstraintMaker.remakeConstraints(self, block: block)
  68. }
  69. #endif
  70. }