MASExampleSidesView.m 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. //
  2. // MASExampleSidesView.m
  3. // Masonry
  4. //
  5. // Created by Jonas Budelmann on 21/07/13.
  6. // Copyright (c) 2013 cloudling. All rights reserved.
  7. //
  8. #import "MASExampleSidesView.h"
  9. @implementation MASExampleSidesView
  10. - (id)init {
  11. self = [super init];
  12. if (!self) return nil;
  13. UIView *lastView = self;
  14. for (int i = 0; i < 10; i++) {
  15. UIView *view = UIView.new;
  16. view.backgroundColor = [self randomColor];
  17. view.layer.borderColor = UIColor.blackColor.CGColor;
  18. view.layer.borderWidth = 2;
  19. [self addSubview:view];
  20. [view mas_makeConstraints:^(MASConstraintMaker *make) {
  21. make.edges.equalTo(lastView).insets(UIEdgeInsetsMake(5, 10, 15, 20));
  22. }];
  23. lastView = view;
  24. }
  25. return self;
  26. }
  27. - (UIColor *)randomColor {
  28. CGFloat hue = ( arc4random() % 256 / 256.0 ); // 0.0 to 1.0
  29. CGFloat saturation = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0, away from white
  30. CGFloat brightness = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0, away from black
  31. return [UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:1];
  32. }
  33. @end