MASExampleLayoutGuideViewController.m 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //
  2. // MASExampleLayoutGuideViewController.m
  3. // Masonry iOS Examples
  4. //
  5. // Created by Jonas Budelmann on 26/11/13.
  6. // Copyright (c) 2013 Jonas Budelmann. All rights reserved.
  7. //
  8. #import "MASExampleLayoutGuideViewController.h"
  9. @interface MASExampleLayoutGuideViewController ()
  10. @end
  11. @implementation MASExampleLayoutGuideViewController
  12. - (id)init {
  13. self = [super init];
  14. if (!self) return nil;
  15. self.title = @"Layout Guides";
  16. return self;
  17. }
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. self.view.backgroundColor = [UIColor whiteColor];
  21. UIView *topView = UIView.new;
  22. topView.backgroundColor = UIColor.greenColor;
  23. topView.layer.borderColor = UIColor.blackColor.CGColor;
  24. topView.layer.borderWidth = 2;
  25. [self.view addSubview:topView];
  26. UIView *bottomView = UIView.new;
  27. bottomView.backgroundColor = UIColor.redColor;
  28. bottomView.layer.borderColor = UIColor.blackColor.CGColor;
  29. bottomView.layer.borderWidth = 2;
  30. [self.view addSubview:bottomView];
  31. // TODO find way that avoids casting
  32. // layoutGuides are actually UIView subclasses so can be used in Masonry
  33. // However casting to UIView is not ideal if Apple decides to change underlying implementation of layoutGuides this will break
  34. [topView makeConstraints:^(MASConstraintMaker *make) {
  35. UIView *topLayoutGuide = (id)self.topLayoutGuide;
  36. make.top.equalTo(topLayoutGuide.bottom);
  37. make.left.equalTo(self.view);
  38. make.right.equalTo(self.view);
  39. make.height.equalTo(@40);
  40. }];
  41. [bottomView makeConstraints:^(MASConstraintMaker *make) {
  42. UIView *bottomLayoutGuide = (id)self.bottomLayoutGuide;
  43. make.bottom.equalTo(bottomLayoutGuide.top);
  44. make.left.equalTo(self.view);
  45. make.right.equalTo(self.view);
  46. make.height.equalTo(@40);
  47. }];
  48. }
  49. @end