-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUIColor+VSClickWheelExtension.m
55 lines (44 loc) · 1.39 KB
/
UIColor+VSClickWheelExtension.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
//
// UIColor+VSClickWheelExtension.m
// VSClickWheel
//
// Created by Manuel Meyer on 18.08.12.
// Copyright (c) 2012 Manuel Meyer. All rights reserved.
//
#import "UIColor+VSClickWheelExtension.h"
@implementation UIColor (VSClickWheelExtension)
- (CGColorSpaceModel) colorSpace
{
CGColorRef clr = [self CGColor];
CGColorSpaceRef clrSpace = CGColorGetColorSpace( clr );
return CGColorSpaceGetModel( clrSpace );
}
-(UIColor *) darken: (CGFloat) amount
{
UIColor *resultColor = self;
CGColorSpaceModel model = [self colorSpace];
int n = CGColorGetNumberOfComponents(self.CGColor);
const CGFloat *components = CGColorGetComponents(self.CGColor);
switch (model) {
case kCGColorSpaceModelRGB:
{
CGFloat red = components[0] - amount;
CGFloat green = components[1] - amount;
CGFloat blue = components[2] - amount;
if (red < 0) red = 0;
if (green < 0) green = 0;
if (blue < 0) blue = 0;
CGFloat alpha;
if (n > 3)
alpha = components[3];
else
alpha = 1.0;
resultColor = [UIColor colorWithRed:red green:green blue:blue alpha:alpha];
break;
}
default:
break;
}
return resultColor;
}
@end