forked from sinuos-zz/shadowsocks-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSWBNewTabButton.m
More file actions
129 lines (101 loc) · 3.73 KB
/
SWBNewTabButton.m
File metadata and controls
129 lines (101 loc) · 3.73 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//
// SWBNewTabButton.m
// SWBuaWeb
//
// Created by clowwindy on 11-6-12.
// Copyright 2011年 __MyCompanyName__. All rights reserved.
//
#import "SWBNewTabButton.h"
@implementation SWBNewTabButton
-(void) loadDefaults {
self.contentMode = UIViewContentModeLeft;
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
[self loadDefaults];
}
return self;
}
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) {
//
[self loadDefaults];
}
return self;
}
#define kCrossFillColor 0.99
#define kCrossPressedFillColor 0.7
#define kCrossStrokeColor 0.1
#define kCrossPressedShadowColor 0.0
#define kCrossShadowColor 1.0
#define kCrossPadding 10
#define kCrossWidth 6
-(void)addCross:(CGContextRef)context width:(CGFloat)width height:(CGFloat)height
{
CGFloat padding = kCrossPadding;
CGFloat crossWidth = kCrossWidth;
CGFloat x1 = padding;
CGFloat x2 = (height - crossWidth) / 2;
CGFloat x3 = x2 + crossWidth;
CGFloat x4 = height - padding;
CGContextMoveToPoint(context, x1, x2);
CGContextAddLineToPoint(context, x1, x3);
CGContextAddLineToPoint(context, x2, x3);
CGContextAddLineToPoint(context, x2, x4);
CGContextAddLineToPoint(context, x3, x4);
CGContextAddLineToPoint(context, x3, x3);
CGContextAddLineToPoint(context, x4, x3);
CGContextAddLineToPoint(context, x4, x2);
CGContextAddLineToPoint(context, x3, x2);
CGContextAddLineToPoint(context, x3, x1);
CGContextAddLineToPoint(context, x2, x1);
CGContextAddLineToPoint(context, x2, x2);
CGContextAddLineToPoint(context, x1, x2);
CGContextClosePath(context);
}
-(void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
//draw circle
CGFloat fillColor = self.highlighted ? kCrossPressedFillColor : kCrossFillColor;
CGFloat fillColorComponents[4] = {
fillColor, fillColor, fillColor, 1.0};
CGFloat strokeColorComponents[4] = {
kCrossStrokeColor, kCrossStrokeColor, kCrossStrokeColor, 1.0};
CGContextSetFillColor(context, fillColorComponents);
CGContextSetStrokeColor(context, strokeColorComponents);
CGContextSetLineWidth(context, 0.5);
CGContextSetLineJoin(context, kCGLineJoinMiter);
CGContextSaveGState(context);
// if (self.highlighted) {
// CGColorSpaceRef myColorspace = CGColorSpaceCreateDeviceRGB();
// CGFloat shadowColorComponents[4] = {
// kCrossPressedShadowColor, kCrossPressedShadowColor, kCrossPressedShadowColor, 1.0};
// CGColorRef myColor = CGColorCreate(myColorspace, shadowColorComponents);
// CGContextSetShadowWithColor(context, CGSizeMake(0, 0), 20, myColor);
// CGColorSpaceRelease(myColorspace);
// CGColorRelease(myColor);
// } else {
// CGColorSpaceRef myColorspace = CGColorSpaceCreateDeviceRGB();
// CGFloat shadowColorComponents[4] = {
// kCrossShadowColor, kCrossShadowColor, kCrossShadowColor, 1.0};
// CGColorRef myColor = CGColorCreate(myColorspace, shadowColorComponents);
// CGContextSetShadowWithColor(context, CGSizeMake(0, 1.5), 0, myColor);
// CGColorSpaceRelease(myColorspace);
// CGColorRelease(myColor);
// }
[self addCross:context width:self.bounds.size.width height:self.bounds.size.height];
CGContextFillPath(context);
CGContextRestoreGState(context);
[self addCross:context width:self.bounds.size.width height:self.bounds.size.height];
CGContextStrokePath(context);
}
-(void)setHighlighted:(BOOL)highlighted {
[super setHighlighted:highlighted];
[self setNeedsDisplay];
}
@end