OLD | NEW |
| (Empty) |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ios/chrome/browser/ui/fancy_ui/tinted_button.h" | |
6 | |
7 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
8 #error "This file requires ARC support." | |
9 #endif | |
10 | |
11 @interface TintedButton () { | |
12 UIColor* normalStateTint_; | |
13 UIColor* highlightedTint_; | |
14 } | |
15 | |
16 // Makes the button's tint color reflect its current state. | |
17 - (void)updateTint; | |
18 | |
19 @end | |
20 | |
21 @implementation TintedButton | |
22 | |
23 - (void)setTintColor:(UIColor*)color forState:(UIControlState)state { | |
24 switch (state) { | |
25 case UIControlStateNormal: | |
26 normalStateTint_ = [color copy]; | |
27 break; | |
28 case UIControlStateHighlighted: | |
29 highlightedTint_ = [color copy]; | |
30 break; | |
31 default: | |
32 return; | |
33 } | |
34 | |
35 if (normalStateTint_ || highlightedTint_) | |
36 self.adjustsImageWhenHighlighted = NO; | |
37 else | |
38 self.adjustsImageWhenHighlighted = YES; | |
39 [self updateTint]; | |
40 } | |
41 | |
42 #pragma mark - UIControl | |
43 | |
44 - (void)setHighlighted:(BOOL)highlighted { | |
45 [super setHighlighted:highlighted]; | |
46 [self updateTint]; | |
47 } | |
48 | |
49 #pragma mark - Private | |
50 | |
51 - (void)updateTint { | |
52 UIColor* newTint = nil; | |
53 switch (self.state) { | |
54 case UIControlStateNormal: | |
55 newTint = normalStateTint_; | |
56 break; | |
57 case UIControlStateHighlighted: | |
58 newTint = highlightedTint_; | |
59 break; | |
60 default: | |
61 newTint = normalStateTint_; | |
62 break; | |
63 } | |
64 self.tintColor = newTint; | |
65 } | |
66 | |
67 @end | |
OLD | NEW |