This repository has been archived by the owner on Mar 9, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WMCircleButton.m
86 lines (64 loc) · 2.32 KB
/
WMCircleButton.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
80
81
82
83
84
85
86
//
// WMCircleButton.m
// WhiteMochaUP
//
// Created by John Liedtke on 6/1/14.
//
//
#import "WMCircleButton.h"
#import <QuartzCore/QuartzCore.h>
@interface WMCircleButton ()
@property (nonatomic, strong) CAShapeLayer *circleLayer;
@property (nonatomic, readwrite) UIColor *color;
@end
@implementation WMCircleButton
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
}
return self;
}
- (void)drawCircleButton:(UIColor *)color title:(NSString *)title
{
self.color = color;
[self setTitle:title forState:UIControlStateNormal];
[self setTitleColor:color forState:UIControlStateNormal];
self.circleLayer = [CAShapeLayer layer];
[self.circleLayer setBounds:CGRectMake(0.0f, 0.0f, [self bounds].size.width,
[self bounds].size.height)];
[self.circleLayer setPosition:CGPointMake(CGRectGetMidX([self bounds]),CGRectGetMidY([self bounds]))];
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, CGRectGetWidth(self.frame), CGRectGetHeight(self.frame))];
[self.circleLayer setPath:[path CGPath]];
[self.circleLayer setStrokeColor:[color CGColor]];
[self.circleLayer setLineWidth:1.5f];
[self.circleLayer setFillColor:[[UIColor clearColor] CGColor]];
[self.layer insertSublayer:self.circleLayer atIndex:0];
}
- (void)setHighlighted:(BOOL)highlighted
{
if (highlighted)
{
[self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[self setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
self.titleLabel.textColor = [UIColor whiteColor];
//self.title.textColor = [UIColor whiteColor];
[self.circleLayer setFillColor:self.color.CGColor];
[self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
}
else
{
[self.circleLayer setFillColor:[UIColor clearColor].CGColor];
[self setTitleColor:self.color forState:UIControlStateNormal];
// [self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
}
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
@end