MASExampleAttributeChainingView.m 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. //
  2. // MASExampleAttributeChainingView.m
  3. // Masonry iOS Examples
  4. //
  5. // Created by Jonas Budelmann on 31/03/14.
  6. // Copyright (c) 2014 Jonas Budelmann. All rights reserved.
  7. //
  8. #import "MASExampleAttributeChainingView.h"
  9. @implementation MASExampleAttributeChainingView
  10. - (id)init {
  11. self = [super init];
  12. if (!self) return nil;
  13. UIView *view1 = UIView.new;
  14. view1.backgroundColor = UIColor.greenColor;
  15. view1.layer.borderColor = UIColor.blackColor.CGColor;
  16. view1.layer.borderWidth = 2;
  17. [self addSubview:view1];
  18. UIView *view2 = UIView.new;
  19. view2.backgroundColor = UIColor.redColor;
  20. view2.layer.borderColor = UIColor.blackColor.CGColor;
  21. view2.layer.borderWidth = 2;
  22. [self addSubview:view2];
  23. UIView *view3 = UIView.new;
  24. view3.backgroundColor = UIColor.blueColor;
  25. view3.layer.borderColor = UIColor.blackColor.CGColor;
  26. view3.layer.borderWidth = 2;
  27. [self addSubview:view3];
  28. UIView *superview = self;
  29. UIEdgeInsets padding = UIEdgeInsetsMake(15, 10, 15, 10);
  30. [view1 mas_makeConstraints:^(MASConstraintMaker *make) {
  31. // chain attributes
  32. make.top.and.left.equalTo(superview).insets(padding);
  33. // which is the equivalent of
  34. // make.top.greaterThanOrEqualTo(superview).insets(padding);
  35. // make.left.greaterThanOrEqualTo(superview).insets(padding);
  36. make.bottom.equalTo(view3.mas_top).insets(padding);
  37. make.right.equalTo(view2.mas_left).insets(padding);
  38. make.width.equalTo(view2.mas_width);
  39. make.height.equalTo(@[view2, view3]);
  40. }];
  41. [view2 mas_makeConstraints:^(MASConstraintMaker *make) {
  42. // chain attributes
  43. make.top.and.right.equalTo(superview).insets(padding);
  44. make.left.equalTo(view1.mas_right).insets(padding);
  45. make.bottom.equalTo(view3.mas_top).insets(padding);
  46. make.width.equalTo(view1.mas_width);
  47. make.height.equalTo(@[view1, view3]);
  48. }];
  49. [view3 mas_makeConstraints:^(MASConstraintMaker *make) {
  50. make.top.equalTo(view1.mas_bottom).insets(padding);
  51. // chain attributes
  52. make.left.right.and.bottom.equalTo(superview).insets(padding);
  53. make.height.equalTo(@[view1, view2]);
  54. }];
  55. return self;
  56. }
  57. @end