MASExampleDebuggingView.m 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. //
  2. // MASExampleDebuggingView.m
  3. // Masonry iOS Examples
  4. //
  5. // Created by Jonas Budelmann on 3/08/13.
  6. // Copyright (c) 2013 Jonas Budelmann. All rights reserved.
  7. //
  8. #import "MASExampleDebuggingView.h"
  9. @implementation MASExampleDebuggingView
  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. UILabel *view3 = UILabel.new;
  24. view3.backgroundColor = UIColor.blueColor;
  25. view3.numberOfLines = 3;
  26. view3.textAlignment = NSTextAlignmentCenter;
  27. view3.font = [UIFont systemFontOfSize:24];
  28. view3.textColor = UIColor.whiteColor;
  29. view3.text = @"this should look broken! check your console!";
  30. view3.layer.borderColor = UIColor.blackColor.CGColor;
  31. view3.layer.borderWidth = 2;
  32. [self addSubview:view3];
  33. UIView *superview = self;
  34. int padding = 10;
  35. //you can attach debug keys to views like so:
  36. // view1.mas_key = @"view1";
  37. // view2.mas_key = @"view2";
  38. // view3.mas_key = @"view3";
  39. // superview.mas_key = @"superview";
  40. //OR you can attach keys automagically like so:
  41. MASAttachKeys(view1, view2, view3, superview);
  42. [view3 mas_makeConstraints:^(MASConstraintMaker *make) {
  43. //you can also attach debug keys to constaints
  44. make.edges.equalTo(@1).key(@"ConflictingConstraint"); //composite constraint keys will be indexed
  45. make.height.greaterThanOrEqualTo(@5000).key(@"ConstantConstraint");
  46. make.top.equalTo(view1.mas_bottom).offset(padding);
  47. make.left.equalTo(superview.mas_left).offset(padding);
  48. make.bottom.equalTo(superview.mas_bottom).offset(-padding).key(@"BottomConstraint");
  49. make.right.equalTo(superview.mas_right).offset(-padding);
  50. make.height.equalTo(view1.mas_height);
  51. make.height.equalTo(view2.mas_height).key(@340954); //anything can be a key
  52. }];
  53. [view1 makeConstraints:^(MASConstraintMaker *make) {
  54. make.top.greaterThanOrEqualTo(superview.top).offset(padding);
  55. make.left.equalTo(superview.left).offset(padding);
  56. make.bottom.equalTo(view3.top).offset(-padding);
  57. make.right.equalTo(view2.left).offset(-padding);
  58. make.width.equalTo(view2.width);
  59. make.height.equalTo(view2.height);
  60. make.height.equalTo(view3.height);
  61. }];
  62. //with is semantic and option
  63. [view2 mas_makeConstraints:^(MASConstraintMaker *make) {
  64. make.top.equalTo(superview.mas_top).with.offset(padding);
  65. make.left.equalTo(view1.mas_right).offset(padding);
  66. make.bottom.equalTo(view3.mas_top).offset(-padding);
  67. make.right.equalTo(superview.mas_right).offset(-padding);
  68. make.width.equalTo(view1.mas_width);
  69. make.height.equalTo(@[view1, view3]);
  70. }];
  71. return self;
  72. }
  73. @end