ViewController.swift 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //
  2. // ViewController.swift
  3. // Snappy
  4. //
  5. // Created by Jonas Budelmann on 25/07/14.
  6. // Copyright (c) 2014 Jonas Budelmann. All rights reserved.
  7. //
  8. import UIKit
  9. class ViewController: UIViewController {
  10. override func viewDidLoad() {
  11. super.viewDidLoad()
  12. let superview: UIView = self.view
  13. let view1 = UIView()
  14. view1.backgroundColor = UIColor.greenColor()
  15. view1.layer.borderColor = UIColor.blackColor().CGColor
  16. view1.layer.borderWidth = 2
  17. superview.addSubview(view1)
  18. let view2 = UIView()
  19. view2.backgroundColor = UIColor.redColor()
  20. view2.layer.borderColor = UIColor.blackColor().CGColor
  21. view2.layer.borderWidth = 2
  22. superview.addSubview(view2)
  23. let view3 = UIView()
  24. view3.backgroundColor = UIColor.blueColor()
  25. view3.layer.borderColor = UIColor.blackColor().CGColor
  26. view3.layer.borderWidth = 2
  27. superview.addSubview(view3)
  28. let padding = UIEdgeInsets(top: 15, left: 10, bottom: 15, right: 10)
  29. view1.mas_makeConstraints { make in
  30. make.top.and.left.greaterThanOrEqualTo(superview).insets(padding)
  31. make.bottom.equalTo(view3.mas_top).insets(padding)
  32. make.right.equalTo(view2.mas_left).insets(padding)
  33. make.width.equalTo(view2.mas_width)
  34. make.height.equalTo([view2, view3])
  35. }
  36. view2.mas_makeConstraints { make in
  37. // chain attributes
  38. make.top.and.right.equalTo(superview).insets(padding)
  39. make.left.equalTo(view1.mas_right).insets(padding)
  40. make.bottom.equalTo(view3.mas_top).insets(padding)
  41. make.width.equalTo(view1.mas_width)
  42. make.height.equalTo([view1, view3])
  43. }
  44. view3.mas_makeConstraints { make in
  45. make.top.equalTo(view1.mas_bottom).insets(padding)
  46. // chain attributes
  47. make.left.right.and.bottom.equalTo(superview).insets(padding)
  48. make.height.equalTo([view1, view2])
  49. }
  50. }
  51. }