No Description

FKRecoCountDownView.m 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. //
  2. // FKRecoCountDownView.m
  3. // FirstLink
  4. //
  5. // Created by ascii on 2016/11/14.
  6. // Copyright © 2016年 FirstLink. All rights reserved.
  7. //
  8. #import "FKRecoCountDownView.h"
  9. @implementation FKRecoTimeUnitView
  10. - (instancetype)init {
  11. self = [super init];
  12. if (self) {
  13. self.backgroundColor = UIColorFromRGB(0xff5656);
  14. [self addSubview:self.timeLabel];
  15. [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  16. make.center.equalTo(self);
  17. }];
  18. }
  19. return self;
  20. }
  21. - (UILabel *)timeLabel {
  22. if (_timeLabel == nil) {
  23. _timeLabel = [[UILabel alloc]init];
  24. _timeLabel.textColor = UIColorFromRGB(0xffffff);
  25. _timeLabel.font = [UIFont systemFontOfSize:(IS_IPHONE_6P ? 10 : 8)];
  26. _timeLabel.textAlignment = NSTextAlignmentCenter;
  27. }
  28. return _timeLabel;
  29. }
  30. @end
  31. @interface FKRecoCountDownView ()
  32. @property (nonatomic, strong) FKRecoTimeUnitView *hourUnitView;
  33. @property (nonatomic, strong) FKRecoTimeUnitView *minuteUnitView;
  34. @property (nonatomic, strong) FKRecoTimeUnitView *secondsUnitView;
  35. @end
  36. @implementation FKRecoCountDownView
  37. /*
  38. // Only override drawRect: if you perform custom drawing.
  39. // An empty implementation adversely affects performance during animation.
  40. - (void)drawRect:(CGRect)rect {
  41. // Drawing code
  42. }
  43. */
  44. - (instancetype)init {
  45. self = [super init];
  46. if (self) {
  47. self.hourUnitView = [self makeTimeUnitView];
  48. self.minuteUnitView = [self makeTimeUnitView];
  49. self.secondsUnitView = [self makeTimeUnitView];
  50. self.backgroundColor = UIColorFromRGB(0xffeae9);
  51. [self addAllSubviews];
  52. }
  53. return self;
  54. }
  55. - (void)setTimeInterval:(NSTimeInterval)ti {
  56. [self refreshTimeWithTimeInterval:ti];
  57. }
  58. - (void)refreshTimeWithTimeInterval:(NSTimeInterval)ti {
  59. NSDateComponents *componets = [FLStringHelper convertSecondToComponents:ti];
  60. self.hourUnitView.timeLabel.text = [NSString stringWithFormat:@"%02ld", componets.hour];
  61. self.minuteUnitView.timeLabel.text = [NSString stringWithFormat:@"%02ld", componets.minute];
  62. self.secondsUnitView.timeLabel.text = [NSString stringWithFormat:@"%02ld", componets.second];
  63. }
  64. #pragma mark - Method
  65. + (CGFloat)height {
  66. if (IS_IPHONE_6P) {
  67. return 16;
  68. } else if (IS_IPHONE_6) {
  69. return 12;
  70. } else {
  71. return 12;
  72. }
  73. }
  74. #pragma mark - Layout
  75. - (void)addAllSubviews {
  76. CGFloat length = [FKRecoCountDownView height];
  77. [self addSubview:self.hourUnitView];
  78. [self.hourUnitView mas_makeConstraints:^(MASConstraintMaker *make) {
  79. make.left.centerY.equalTo(self);
  80. make.size.mas_equalTo(CGSizeMake(length, length));
  81. }];
  82. UIView *leftDotView = [self makeDotView];
  83. [self addSubview:leftDotView];
  84. [leftDotView mas_makeConstraints:^(MASConstraintMaker *make) {
  85. make.centerY.equalTo(self.hourUnitView);
  86. make.left.equalTo(self.hourUnitView.mas_right);
  87. make.size.mas_equalTo(CGSizeMake(8, 19));
  88. }];
  89. [self addSubview:self.minuteUnitView];
  90. [self.minuteUnitView mas_makeConstraints:^(MASConstraintMaker *make) {
  91. make.centerY.equalTo(self.hourUnitView);
  92. make.left.equalTo(leftDotView.mas_right);
  93. make.size.equalTo(self.hourUnitView);
  94. }];
  95. UIView *rightDotView = [self makeDotView];
  96. [self addSubview:rightDotView];
  97. [rightDotView mas_makeConstraints:^(MASConstraintMaker *make) {
  98. make.centerY.equalTo(self.minuteUnitView);
  99. make.left.equalTo(self.minuteUnitView.mas_right);
  100. make.size.equalTo(leftDotView);
  101. }];
  102. [self addSubview:self.secondsUnitView];
  103. [self.secondsUnitView mas_makeConstraints:^(MASConstraintMaker *make) {
  104. make.centerY.equalTo(self.hourUnitView);
  105. make.left.equalTo(rightDotView.mas_right);
  106. make.size.equalTo(self.hourUnitView);
  107. }];
  108. }
  109. #pragma mark - Property
  110. - (FKRecoTimeUnitView *)makeTimeUnitView {
  111. return [[FKRecoTimeUnitView alloc] init];
  112. }
  113. - (UILabel *)makeDotView {
  114. UILabel *label = [UILabel new];
  115. label.textColor = UIColorFromRGB(0xff2c6b);
  116. label.font = [UIFont systemFontOfSize:13];
  117. label.textAlignment = NSTextAlignmentCenter;
  118. label.text = @":";
  119. return label;
  120. }
  121. @end