-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
Copy pathSWBSmallCloseButtonHighlightView.m
79 lines (55 loc) · 2.13 KB
/
SWBSmallCloseButtonHighlightView.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//
// SWBSmallCloseButtonHighlightView.m
// SWBuaWeb
//
// Created by clowwindy on 11-6-10.
// Copyright 2011年 __MyCompanyName__. All rights reserved.
//
#import "SWBSmallCloseButtonHighlightView.h"
@implementation SWBSmallCloseButtonHighlightView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
#define kButtonBGColor 0.1
#define kButtonFGColor 0.9
#define kButtonLineWidth 2
#define kButtonShadowColor 0.0
#define kButtonHighlightedScale 1.5
-(void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
CGColorSpaceRef myColorspace = CGColorSpaceCreateDeviceRGB();
CGFloat height = self.bounds.size.height;
CGFloat width = self.bounds.size.width;
CGFloat radiusToDraw = 8;
//draw circle
CGContextAddArc(context, width / 2, height / 2, radiusToDraw, 0, 2 * M_PI, 0);
CGFloat shadowColorComponents[4] = {
kButtonShadowColor, kButtonShadowColor, kButtonShadowColor, 1.0};
CGColorRef myColor = CGColorCreate(myColorspace, shadowColorComponents);
CGContextSetShadowWithColor(context, CGSizeMake(0, 0), 20, myColor);
CGColorRelease(myColor);
CGFloat bgColorComponents[4] = {
kButtonBGColor, kButtonBGColor, kButtonBGColor, 1.0};
CGContextSetFillColor(context, bgColorComponents);
CGContextFillPath(context);
// draw x
CGFloat centerX = width / 2;
CGFloat centerY = height / 2;
CGFloat delta = radiusToDraw / 2.2;
CGContextMoveToPoint(context, centerX - delta, centerY - delta);
CGContextAddLineToPoint(context, centerX + delta, centerY + delta);
CGContextMoveToPoint(context, centerX - delta, centerY + delta);
CGContextAddLineToPoint(context, centerX + delta, centerY - delta);
CGFloat fgColorComponents[4] = {
kButtonFGColor, kButtonFGColor, kButtonFGColor, 1.0};
CGContextSetStrokeColor(context, fgColorComponents);
CGContextSetLineWidth(context, kButtonLineWidth);
CGContextStrokePath(context);
CGColorSpaceRelease(myColorspace);
}
@end