123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- //
- // FKRecoCountDownView.m
- // FirstLink
- //
- // Created by ascii on 2016/11/14.
- // Copyright © 2016年 FirstLink. All rights reserved.
- //
- #import "FKRecoCountDownView.h"
- @implementation FKRecoTimeUnitView
- - (instancetype)init {
- self = [super init];
- if (self) {
- self.backgroundColor = UIColorFromRGB(0xff5656);
-
- [self addSubview:self.timeLabel];
- [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.center.equalTo(self);
- }];
- }
- return self;
- }
- - (UILabel *)timeLabel {
- if (_timeLabel == nil) {
- _timeLabel = [[UILabel alloc]init];
- _timeLabel.textColor = UIColorFromRGB(0xffffff);
- _timeLabel.font = [UIFont systemFontOfSize:(IS_IPHONE_6P ? 10 : 8)];
- _timeLabel.textAlignment = NSTextAlignmentCenter;
- }
- return _timeLabel;
- }
- @end
- @interface FKRecoCountDownView ()
- @property (nonatomic, strong) FKRecoTimeUnitView *hourUnitView;
- @property (nonatomic, strong) FKRecoTimeUnitView *minuteUnitView;
- @property (nonatomic, strong) FKRecoTimeUnitView *secondsUnitView;
- @end
- @implementation FKRecoCountDownView
- /*
- // Only override drawRect: if you perform custom drawing.
- // An empty implementation adversely affects performance during animation.
- - (void)drawRect:(CGRect)rect {
- // Drawing code
- }
- */
- - (instancetype)init {
- self = [super init];
- if (self) {
- self.hourUnitView = [self makeTimeUnitView];
- self.minuteUnitView = [self makeTimeUnitView];
- self.secondsUnitView = [self makeTimeUnitView];
-
- self.backgroundColor = UIColorFromRGB(0xffeae9);
-
- [self addAllSubviews];
- }
- return self;
- }
- - (void)setTimeInterval:(NSTimeInterval)ti {
- [self refreshTimeWithTimeInterval:ti];
- }
- - (void)refreshTimeWithTimeInterval:(NSTimeInterval)ti {
- NSDateComponents *componets = [FLStringHelper convertSecondToComponents:ti];
-
- self.hourUnitView.timeLabel.text = [NSString stringWithFormat:@"%02ld", componets.hour];
- self.minuteUnitView.timeLabel.text = [NSString stringWithFormat:@"%02ld", componets.minute];
- self.secondsUnitView.timeLabel.text = [NSString stringWithFormat:@"%02ld", componets.second];
- }
- #pragma mark - Method
- + (CGFloat)height {
- if (IS_IPHONE_6P) {
- return 16;
- } else if (IS_IPHONE_6) {
- return 12;
- } else {
- return 12;
- }
- }
- #pragma mark - Layout
- - (void)addAllSubviews {
- CGFloat length = [FKRecoCountDownView height];
-
- [self addSubview:self.hourUnitView];
- [self.hourUnitView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.centerY.equalTo(self);
- make.size.mas_equalTo(CGSizeMake(length, length));
- }];
-
- UIView *leftDotView = [self makeDotView];
- [self addSubview:leftDotView];
- [leftDotView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(self.hourUnitView);
- make.left.equalTo(self.hourUnitView.mas_right);
- make.size.mas_equalTo(CGSizeMake(8, 19));
- }];
-
- [self addSubview:self.minuteUnitView];
- [self.minuteUnitView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(self.hourUnitView);
- make.left.equalTo(leftDotView.mas_right);
- make.size.equalTo(self.hourUnitView);
- }];
-
- UIView *rightDotView = [self makeDotView];
- [self addSubview:rightDotView];
- [rightDotView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(self.minuteUnitView);
- make.left.equalTo(self.minuteUnitView.mas_right);
- make.size.equalTo(leftDotView);
- }];
-
- [self addSubview:self.secondsUnitView];
- [self.secondsUnitView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(self.hourUnitView);
- make.left.equalTo(rightDotView.mas_right);
- make.size.equalTo(self.hourUnitView);
- }];
- }
- #pragma mark - Property
- - (FKRecoTimeUnitView *)makeTimeUnitView {
- return [[FKRecoTimeUnitView alloc] init];
- }
- - (UILabel *)makeDotView {
- UILabel *label = [UILabel new];
- label.textColor = UIColorFromRGB(0xff2c6b);
- label.font = [UIFont systemFontOfSize:13];
- label.textAlignment = NSTextAlignmentCenter;
- label.text = @":";
- return label;
- }
- @end
|