-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathCBRGradientView.m
More file actions
46 lines (38 loc) · 870 Bytes
/
CBRGradientView.m
File metadata and controls
46 lines (38 loc) · 870 Bytes
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
#import "CBRGradientView.h"
@implementation CBRGradientView
+ (Class)layerClass {
return [CAGradientLayer class];
}
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.opaque = NO;
}
return self;
}
- (void)setSolidColor:(UIColor *)color {
self.backgroundColor = color;
if (color) {
[self setColors:nil];
}
}
- (void)setColors:(NSArray *)colors {
[colors retain];
[_colors release];
_colors = colors;
[self refreshGradientLayer];
if (colors) {
self.backgroundColor = nil;
}
}
- (void)refreshGradientLayer {
CAGradientLayer *gradientLayer = (CAGradientLayer *)self.layer;
gradientLayer.colors = _colors;
gradientLayer.startPoint = CGPointMake(0.0, 0.5);
gradientLayer.endPoint = CGPointMake(1.0, 0.5);
}
- (void)dealloc {
[_colors release];
[super dealloc];
}
@end