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 #import "base/mac/scoped_nsobject.h" |
| 8 |
| 9 @interface TintedButton () { |
| 10 base::scoped_nsobject<UIColor> normalStateTint_; |
| 11 base::scoped_nsobject<UIColor> highlightedTint_; |
| 12 } |
| 13 |
| 14 // Makes the button's tint color reflect its current state. |
| 15 - (void)updateTint; |
| 16 |
| 17 @end |
| 18 |
| 19 @implementation TintedButton |
| 20 |
| 21 - (void)setTintColor:(UIColor*)color forState:(UIControlState)state { |
| 22 switch (state) { |
| 23 case UIControlStateNormal: |
| 24 normalStateTint_.reset([color copy]); |
| 25 break; |
| 26 case UIControlStateHighlighted: |
| 27 highlightedTint_.reset([color copy]); |
| 28 break; |
| 29 default: |
| 30 return; |
| 31 } |
| 32 |
| 33 if (normalStateTint_ || highlightedTint_) |
| 34 self.adjustsImageWhenHighlighted = NO; |
| 35 else |
| 36 self.adjustsImageWhenHighlighted = YES; |
| 37 [self updateTint]; |
| 38 } |
| 39 |
| 40 #pragma mark - UIControl |
| 41 |
| 42 - (void)setHighlighted:(BOOL)highlighted { |
| 43 [super setHighlighted:highlighted]; |
| 44 [self updateTint]; |
| 45 } |
| 46 |
| 47 #pragma mark - Private |
| 48 |
| 49 - (void)updateTint { |
| 50 UIColor* newTint = nil; |
| 51 switch (self.state) { |
| 52 case UIControlStateNormal: |
| 53 newTint = normalStateTint_.get(); |
| 54 break; |
| 55 case UIControlStateHighlighted: |
| 56 newTint = highlightedTint_.get(); |
| 57 break; |
| 58 default: |
| 59 newTint = normalStateTint_.get(); |
| 60 break; |
| 61 } |
| 62 self.tintColor = newTint; |
| 63 } |
| 64 |
| 65 @end |
OLD | NEW |