-
Notifications
You must be signed in to change notification settings - Fork 0
/
CrazyBackgroundView.m
80 lines (63 loc) · 4.85 KB
/
CrazyBackgroundView.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//
// CrazyBackgroundView.m
// Drawing
//
// Created by Richie Davis on 2/18/16.
// Copyright © 2016 Claire. All rights reserved.
//
#import "CrazyBackgroundView.h"
@implementation CrazyBackgroundView
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
-(void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
UIColor *flatBlueColor = [UIColor colorWithRed:0.18 green:0.525 blue:0.671 alpha:1];
UIColor *paleYellowColor = [UIColor colorWithRed:0.965 green:0.961 blue:0.682 alpha:1];
UIColor *brightYellowColor = [UIColor colorWithRed:0.961 green:0.969 blue:0.286 alpha:1];
UIColor *flatRedColor = [UIColor colorWithRed:0.949 green:0.259 blue:0.212 alpha:1];
UIColor *flatGrayColor = [UIColor colorWithRed:0.337 green:0.333 blue:0.329 alpha:1];
CGContextSetFillColorWithColor(context, flatBlueColor.CGColor);
CGContextFillRect(context, self.bounds);
CGFloat viewWidth = self.bounds.size.width;
CGFloat viewHeight = self.bounds.size.height;
CGFloat wideSquareWidth = viewWidth / 4;
CGFloat tallSquareHeight = viewHeight / 2;
CGFloat thinSquareWidth = viewWidth / 8;
CGFloat shortSquareHeight = viewHeight / 4;
//wide & tall row
[self squareWithWidth:wideSquareWidth andHeight:tallSquareHeight andX:0 andY:0 andColor:flatBlueColor andContext:context];
[self squareWithWidth:wideSquareWidth andHeight:tallSquareHeight andX:wideSquareWidth andY:0 andColor:paleYellowColor andContext:context];
[self squareWithWidth:wideSquareWidth andHeight:tallSquareHeight andX:wideSquareWidth * 2 andY:0 andColor:flatRedColor andContext:context];
[self squareWithWidth:wideSquareWidth andHeight:tallSquareHeight andX:wideSquareWidth * 3 andY:0 andColor:flatGrayColor andContext:context];
//thin and short rows
[self squareWithWidth:thinSquareWidth andHeight:shortSquareHeight andX:0 andY:tallSquareHeight andColor:paleYellowColor andContext:context];
[self squareWithWidth:thinSquareWidth andHeight:shortSquareHeight andX:thinSquareWidth andY:tallSquareHeight andColor:flatRedColor andContext:context];
[self squareWithWidth:thinSquareWidth andHeight:shortSquareHeight andX:thinSquareWidth * 2 andY:tallSquareHeight andColor:flatGrayColor andContext:context];
[self squareWithWidth:thinSquareWidth andHeight:shortSquareHeight andX:thinSquareWidth * 3 andY:tallSquareHeight andColor:flatBlueColor andContext:context];
[self squareWithWidth:thinSquareWidth andHeight:shortSquareHeight andX:thinSquareWidth * 4 andY:tallSquareHeight andColor:brightYellowColor andContext:context];
[self squareWithWidth:thinSquareWidth andHeight:shortSquareHeight andX:thinSquareWidth * 5 andY:tallSquareHeight andColor:flatGrayColor andContext:context];
[self squareWithWidth:thinSquareWidth andHeight:shortSquareHeight andX:thinSquareWidth * 6 andY:tallSquareHeight andColor:flatBlueColor andContext:context];
[self squareWithWidth:thinSquareWidth andHeight:shortSquareHeight andX:thinSquareWidth * 7 andY:tallSquareHeight andColor:flatRedColor andContext:context];
[self squareWithWidth:thinSquareWidth andHeight:shortSquareHeight andX:0 andY:tallSquareHeight + shortSquareHeight andColor:brightYellowColor andContext:context];
[self squareWithWidth:thinSquareWidth andHeight:shortSquareHeight andX:thinSquareWidth andY:tallSquareHeight + shortSquareHeight andColor:flatGrayColor andContext:context];
[self squareWithWidth:thinSquareWidth andHeight:shortSquareHeight andX:thinSquareWidth * 2 andY:tallSquareHeight + shortSquareHeight andColor:flatBlueColor andContext:context];
[self squareWithWidth:thinSquareWidth andHeight:shortSquareHeight andX:thinSquareWidth * 3 andY:tallSquareHeight + shortSquareHeight andColor:flatRedColor andContext:context];
[self squareWithWidth:thinSquareWidth andHeight:shortSquareHeight andX:thinSquareWidth * 4 andY:tallSquareHeight + shortSquareHeight andColor:flatBlueColor andContext:context];
[self squareWithWidth:thinSquareWidth andHeight:shortSquareHeight andX:thinSquareWidth * 5 andY:tallSquareHeight + shortSquareHeight andColor:paleYellowColor andContext:context];
[self squareWithWidth:thinSquareWidth andHeight:shortSquareHeight andX:thinSquareWidth * 6 andY:tallSquareHeight + shortSquareHeight andColor:brightYellowColor andContext:context];
[self squareWithWidth:thinSquareWidth andHeight:shortSquareHeight andX:thinSquareWidth * 7 andY:tallSquareHeight + shortSquareHeight andColor:flatBlueColor andContext:context];
}
-(CGRect)squareWithWidth: (CGFloat)width andHeight: (CGFloat)height andX: (CGFloat)x andY: (CGFloat)Y andColor:(UIColor*)color andContext:(CGContextRef)context
{
CGRect returnRect = CGRectMake(x, Y, width, height);
CGContextSetFillColorWithColor(context, color.CGColor);
CGContextFillRect(context, returnRect);
return returnRect;
}
@end