forked from soffes/cheddar-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CDIViewArchiveButton.m
64 lines (49 loc) · 1.96 KB
/
CDIViewArchiveButton.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
//
// CDIViewArchiveButton.m
// Cheddar for iOS
//
// Created by Sam Soffes on 1/19/13.
// Copyright (c) 2013 Nothing Magical. All rights reserved.
//
#import "CDIViewArchiveButton.h"
#import "UIColor+CheddariOSAdditions.h"
#import "UIFont+CheddariOSAdditions.h"
@interface CDIViewArchiveButton ()
@property (nonatomic, strong) UIImageView *disclosureImageView;
@end
@implementation CDIViewArchiveButton
#pragma mark - UIView
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
self.contentMode = UIViewContentModeRedraw;
[self setTitleColor:[[UIColor cheddarSteelColor] colorWithAlphaComponent:0.5f] forState:UIControlStateNormal];
[self setTitleColor:[UIColor cheddarSteelColor] forState:UIControlStateHighlighted];
self.titleLabel.font = [UIFont cheddarInterfaceFontOfSize:14.0f];
self.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
self.titleEdgeInsets = UIEdgeInsetsMake(0.0f, 10.0f, 0.0f, 0.0f);
_disclosureImageView = [[UIImageView alloc] init];
_disclosureImageView.image = [UIImage imageNamed:@"disclosure"];
_disclosureImageView.highlightedImage = [UIImage imageNamed:@"disclosure-highlighted"];
_disclosureImageView.alpha = 0.5f;
[self addSubview:_disclosureImageView];
}
return self;
}
- (void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
UIColor *color = self.highlighted ? [UIColor colorWithWhite:0.945f alpha:1.0f] : [UIColor colorWithWhite:0.957f alpha:1.0f];
[color setFill];
SSDrawRoundedRect(context, self.bounds, roundf(self.bounds.size.height / 2.0f));
}
- (void)layoutSubviews {
[super layoutSubviews];
CGSize size = self.bounds.size;
self.disclosureImageView.frame = CGRectMake(size.width - 20.0f, roundf((size.height - 15.0f) / 2.0f), 10.0f, 15.0f);
}
#pragma mark - UIControl
- (void)setHighlighted:(BOOL)highlighted {
[super setHighlighted:highlighted];
self.disclosureImageView.alpha = highlighted ? 1.0f : 0.5f;
[self setNeedsDisplay];
}
@end