MASExampleConstantsView.m 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. //
  2. // MASExampleConstantsView.m
  3. // Masonry
  4. //
  5. // Created by Jonas Budelmann on 21/07/13.
  6. // Copyright (c) 2013 cloudling. All rights reserved.
  7. //
  8. #import "MASExampleConstantsView.h"
  9. @implementation MASExampleConstantsView
  10. - (id)init {
  11. self = [super init];
  12. if (!self) return nil;
  13. UIView *view1 = UIView.new;
  14. view1.backgroundColor = UIColor.purpleColor;
  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.orangeColor;
  20. view2.layer.borderColor = UIColor.blackColor.CGColor;
  21. view2.layer.borderWidth = 2;
  22. [self addSubview:view2];
  23. //example of using constants
  24. [view1 mas_makeConstraints:^(MASConstraintMaker *make) {
  25. make.top.equalTo(@20);
  26. make.left.equalTo(@20);
  27. make.bottom.equalTo(@-20);
  28. make.right.equalTo(@-20);
  29. }];
  30. // auto-boxing macros allow you to simply use scalars and structs, they will be wrapped automatically
  31. [view2 mas_makeConstraints:^(MASConstraintMaker *make) {
  32. make.center.equalTo(CGPointMake(0, 50));
  33. make.size.equalTo(CGSizeMake(200, 100));
  34. }];
  35. return self;
  36. }
  37. @end