-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGradientView.m
More file actions
66 lines (51 loc) · 1.52 KB
/
GradientView.m
File metadata and controls
66 lines (51 loc) · 1.52 KB
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
//
// GradientView.m
// Quilters_App
//
// Created by Dan Selig on 08/17/2013.
// Copyright (c) 2013 Dan Selig. All rights reserved.
//
#import "GradientView.h"
@interface GradientView ()
@end
@implementation GradientView
- (void) drawGradient
{
[self drawRect:self.bounds];
}
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
if (! context) return;
CGFloat colors[8];
CGFloat hue;
CGFloat saturation;
CGFloat brightness;
CGFloat red;
CGFloat green;
CGFloat blue;
CGFloat alpha;
[self.color getHue:&hue saturation:&saturation brightness:&brightness alpha:&alpha];
brightness = 1.0;
UIColor *color = [UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:1.0];
[color getRed:&red green:&green blue:&blue alpha:&alpha];
colors[0] = red;
colors[1] = green;
colors[2] = blue;
colors[3] = 1.0;
brightness = 0.1;
color = [UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:1.0];
[color getRed:&red green:&green blue:&blue alpha:&alpha];
colors[4] = red;
colors[5] = green;
colors[6] = blue;
colors[7] = 1.0;
CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB();
CGGradientRef gradient = CGGradientCreateWithColorComponents(rgb, colors, NULL, 2);
CGColorSpaceRelease(rgb);
CGPoint start = CGPointZero;
CGPoint end = CGPointMake(self.bounds.size.width, 0);
CGContextDrawLinearGradient(context, gradient, start, end, 0);
CGGradientRelease(gradient);
}
@end