RootViewController.swift 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //
  2. // RootViewController.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 RootViewController : UIViewController {
  10. override func viewDidLoad() {
  11. self.view.backgroundColor = UIColor.whiteColor()
  12. let superview = 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. var padding = 10;
  29. installConstraints([
  30. view1.left == superview.left + padding
  31. ])
  32. // //if you want to use Masonry without the mas_ prefix
  33. // //define MAS_SHORTHAND before importing Masonry.h see Masonry iOS Examples-Prefix.pch
  34. // [view1 makeConstraints:^(MASConstraintMaker *make) {
  35. // make.top.greaterThanOrEqualTo(superview.top).offset(padding);
  36. // make.left.equalTo(superview.left).offset(padding);
  37. // make.bottom.equalTo(view3.top).offset(-padding);
  38. // make.right.equalTo(view2.left).offset(-padding);
  39. // make.width.equalTo(view2.width);
  40. //
  41. // make.height.equalTo(view2.height);
  42. // make.height.equalTo(view3.height);
  43. // }];
  44. //
  45. // //with is semantic and option
  46. // [view2 mas_makeConstraints:^(MASConstraintMaker *make) {
  47. // make.top.equalTo(superview.mas_top).with.offset(padding); //with with
  48. // make.left.equalTo(view1.mas_right).offset(padding); //without with
  49. // make.bottom.equalTo(view3.mas_top).offset(-padding);
  50. // make.right.equalTo(superview.mas_right).offset(-padding);
  51. // make.width.equalTo(view1.mas_width);
  52. //
  53. // make.height.equalTo(@[view1, view3]); //can pass array of views
  54. // }];
  55. //
  56. // [view3 mas_makeConstraints:^(MASConstraintMaker *make) {
  57. // make.top.equalTo(view1.mas_bottom).offset(padding);
  58. // make.left.equalTo(superview.mas_left).offset(padding);
  59. // make.bottom.equalTo(superview.mas_bottom).offset(-padding);
  60. // make.right.equalTo(superview.mas_right).offset(-padding);
  61. // make.height.equalTo(@[view1.mas_height, view2.mas_height]); //can pass array of attributes
  62. // }];
  63. }
  64. }