TOPasscodeCircleView.m 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //
  2. // TOPasscodeCircleView.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 "TOPasscodeCircleView.h"
  23. @interface TOPasscodeCircleView ()
  24. @property (nonatomic, strong) UIImageView *bottomView;
  25. @property (nonatomic, strong) UIImageView *topView;
  26. @end
  27. @implementation TOPasscodeCircleView
  28. - (instancetype)initWithFrame:(CGRect)frame
  29. {
  30. if (self = [super initWithFrame:frame]) {
  31. self.userInteractionEnabled = NO;
  32. self.bottomView = [[UIImageView alloc] initWithFrame:self.bounds];
  33. self.bottomView.userInteractionEnabled = NO;
  34. self.bottomView.contentMode = UIViewContentModeCenter;
  35. self.bottomView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  36. [self addSubview:self.bottomView];
  37. self.topView = [[UIImageView alloc] initWithFrame:self.bounds];
  38. self.topView.userInteractionEnabled = NO;
  39. self.topView.contentMode = UIViewContentModeCenter;
  40. self.topView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  41. self.topView.alpha = 0.0f;
  42. [self addSubview:self.topView];
  43. }
  44. return self;
  45. }
  46. - (void)setIsHighlighted:(BOOL)isHighlighted
  47. {
  48. [self setHighlighted:isHighlighted animated:NO];
  49. }
  50. - (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
  51. {
  52. if (highlighted == self.isHighlighted) { return; }
  53. _isHighlighted = highlighted;
  54. void (^animationBlock)(void) = ^{
  55. self.topView.alpha = highlighted ? 1.0f : 0.0f;
  56. };
  57. if (!animated) {
  58. animationBlock();
  59. return;
  60. }
  61. [UIView animateWithDuration:0.45f animations:animationBlock];
  62. }
  63. - (void)setCircleImage:(UIImage *)circleImage
  64. {
  65. _circleImage = circleImage;
  66. self.bottomView.image = circleImage;
  67. }
  68. - (void)setHighlightedCircleImage:(UIImage *)highlightedCircleImage
  69. {
  70. _highlightedCircleImage = highlightedCircleImage;
  71. self.topView.image = highlightedCircleImage;
  72. }
  73. @end