TOPasscodeSettingsKeypadButton.m 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //
  2. // TOPasscodeSettingsKeypadButton.m
  3. //
  4. // Copyright 2017 Timothy Oliver. All rights reserved.
  5. //
  6. // Permission is hereby granted, free of charge, to any person obtaining a copy
  7. // of this software and associated documentation files (the "Software"), to
  8. // deal in the Software without restriction, including without limitation the
  9. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  10. // sell copies of the Software, and to permit persons to whom the Software is
  11. // furnished to do so, subject to the following conditions:
  12. //
  13. // The above copyright notice and this permission notice shall be included in
  14. // all copies or substantial portions of the Software.
  15. //
  16. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  17. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  20. // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
  21. // IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. #import "TOPasscodeSettingsKeypadButton.h"
  23. #import "TOPasscodeButtonLabel.h"
  24. @interface TOPasscodeSettingsKeypadButton ()
  25. @property (nonatomic, strong, readwrite) TOPasscodeButtonLabel *buttonLabel;
  26. @end
  27. @implementation TOPasscodeSettingsKeypadButton
  28. + (TOPasscodeSettingsKeypadButton *)button
  29. {
  30. TOPasscodeSettingsKeypadButton *button = [TOPasscodeSettingsKeypadButton buttonWithType:UIButtonTypeCustom];
  31. button.frame = CGRectMake(0,0,100,60);
  32. return button;
  33. }
  34. #pragma mark - Lazy Accessor -
  35. - (TOPasscodeButtonLabel *)buttonLabel
  36. {
  37. if (_buttonLabel) { return _buttonLabel; }
  38. CGRect frame = self.bounds;
  39. frame.size.height -= self.bottomInset;
  40. _buttonLabel = [[TOPasscodeButtonLabel alloc] initWithFrame:frame];
  41. _buttonLabel.userInteractionEnabled = NO;
  42. _buttonLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  43. [self addSubview:_buttonLabel];
  44. return _buttonLabel;
  45. }
  46. #pragma mark - Layout Accessor -
  47. - (void)setBottomInset:(CGFloat)bottomInset
  48. {
  49. _bottomInset = bottomInset;
  50. CGRect frame = self.bounds;
  51. frame.size.height -= _bottomInset;
  52. self.buttonLabel.frame = frame;
  53. [self setNeedsLayout];
  54. }
  55. #pragma mark - Control Accessor -
  56. - (void)setEnabled:(BOOL)enabled
  57. {
  58. [super setEnabled:enabled];
  59. self.buttonLabel.alpha = enabled ? 1.0f : 0.5f;
  60. }
  61. #pragma mark - Background Image Accessor -
  62. - (void)setHighlighted:(BOOL)highlighted {
  63. [self.layer removeAllAnimations];
  64. [UIView transitionWithView:self
  65. duration:0.25
  66. options:UIViewAnimationOptionTransitionCrossDissolve |
  67. UIViewAnimationOptionAllowAnimatedContent |
  68. UIViewAnimationOptionAllowUserInteraction
  69. animations:^{
  70. [super setHighlighted:highlighted];
  71. } completion:nil];
  72. }
  73. - (void)setButtonBackgroundImage:(UIImage *)buttonBackgroundImage
  74. {
  75. [self setBackgroundImage:buttonBackgroundImage forState:UIControlStateNormal];
  76. }
  77. - (UIImage *)buttonBackgroundImage { return [self backgroundImageForState:UIControlStateNormal]; }
  78. - (void)setButtonTappedBackgroundImage:(UIImage *)buttonTappedBackgroundImage
  79. {
  80. [self setBackgroundImage:buttonTappedBackgroundImage forState:UIControlStateHighlighted];
  81. }
  82. - (UIImage *)buttonTappedBackgroundImage { return [self backgroundImageForState:UIControlStateHighlighted]; }
  83. @end