forked from InfinitApps/InfColorPicker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInfColorIndicatorView.m
More file actions
92 lines (65 loc) · 2.4 KB
/
Copy pathInfColorIndicatorView.m
File metadata and controls
92 lines (65 loc) · 2.4 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//==============================================================================
//
// InfColorIndicatorView.m
// InfColorPicker
//
// Created by Troy Gaul on 8/10/10.
//
// Copyright (c) 2011 InfinitApps LLC - http://infinitapps.com
// Some rights reserved: http://opensource.org/licenses/MIT
//
//==============================================================================
#import "InfColorIndicatorView.h"
//==============================================================================
@implementation InfColorIndicatorView
//------------------------------------------------------------------------------
@synthesize color;
//------------------------------------------------------------------------------
- (id) initWithFrame: (CGRect) frame
{
self = [ super initWithFrame: frame ];
if( self ) {
self.opaque = NO;
self.userInteractionEnabled = NO;
}
return self;
}
//------------------------------------------------------------------------------
- (void) dealloc
{
[ color release ];
[ super dealloc ];
}
//------------------------------------------------------------------------------
- (void) setColor: (UIColor*) newColor
{
if( ![ color isEqual: newColor ] ) {
[ color release ];
color = [ newColor retain ];
[ self setNeedsDisplay ];
}
}
//------------------------------------------------------------------------------
- (void) drawRect: (CGRect) rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGPoint center = { CGRectGetMidX( self.bounds ), CGRectGetMidY( self.bounds ) };
CGFloat radius = CGRectGetMidX( self.bounds );
// Fill it:
CGContextAddArc( context, center.x, center.y, radius - 1.0f, 0.0f, 2.0f * (float) M_PI, YES );
[ self.color setFill ];
CGContextFillPath( context );
// Stroke it (black transucent, inner):
CGContextAddArc( context, center.x, center.y, radius - 1.0f, 0.0f, 2.0f * (float) M_PI, YES );
CGContextSetGrayStrokeColor( context, 0.0f, 0.5f );
CGContextSetLineWidth( context, 2.0f );
CGContextStrokePath( context );
// Stroke it (white, outer):
CGContextAddArc( context, center.x, center.y, radius - 2.0f, 0.0f, 2.0f * (float) M_PI, YES );
CGContextSetGrayStrokeColor( context, 1.0f, 1.0f );
CGContextSetLineWidth( context, 2.0f );
CGContextStrokePath( context );
}
//------------------------------------------------------------------------------
@end
//==============================================================================