Files
yinmeng-ios/xplan-ios/Main/Mine/View/SubViews/AnchorLevel/AnchorLevelTimeView.m
2023-01-04 14:14:33 +08:00

260 lines
8.2 KiB
Objective-C

//
// AnchorLevelTimeView.m
// xplan-ios
//
// Created by 冯硕 on 2022/12/13.
//
#import "AnchorLevelTimeView.h"
///Third
#import <Masonry/Masonry.h>
///Tool
#import "ThemeColor.h"
@interface AnchorLevelTimeView ()
///第一个小时
@property (nonatomic,strong) UILabel *firstHourLabel;
///第二个小时
@property (nonatomic,strong) UILabel *secondHourLabel;
///时
@property (nonatomic,strong) UILabel *hourLabel;
///第一个分钟
@property (nonatomic,strong) UILabel *firstMinuteLabel;
///第二个分钟
@property (nonatomic,strong) UILabel *secondMinuteLabel;
///分
@property (nonatomic,strong) UILabel *minuteLabel;
///第一个秒
@property (nonatomic,strong) UILabel *firstSecondLabel;
///第二个秒
@property (nonatomic,strong) UILabel *secondSecondabel;
///秒
@property (nonatomic,strong) UILabel *secondsLabel;
@end
@implementation AnchorLevelTimeView
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self initSubViews];
[self initSubViewConstraints];
}
return self;
}
#pragma mark - Private Method
- (void)initSubViews {
[self addSubview:self.firstHourLabel];
[self addSubview:self.secondHourLabel];
[self addSubview:self.hourLabel];
[self addSubview:self.firstMinuteLabel];
[self addSubview:self.secondMinuteLabel];
[self addSubview:self.minuteLabel];
[self addSubview:self.firstSecondLabel];
[self addSubview:self.secondSecondabel];
[self addSubview:self.secondsLabel];
}
- (void)initSubViewConstraints {
[self.firstHourLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(24, 24));
make.top.mas_equalTo(self);
make.left.mas_equalTo(self).offset(44);
}];
[self.secondHourLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.centerY.mas_equalTo(self.firstHourLabel);
make.left.mas_equalTo(self.firstHourLabel.mas_right).offset(4);
}];
[self.hourLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(self.firstHourLabel);
make.width.mas_equalTo(20);
make.left.mas_equalTo(self.secondHourLabel.mas_right);
}];
[self.firstMinuteLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.centerY.mas_equalTo(self.firstHourLabel);
make.left.mas_equalTo(self.hourLabel.mas_right).offset(0);
}];
[self.secondMinuteLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.centerY.mas_equalTo(self.firstHourLabel);
make.left.mas_equalTo(self.firstMinuteLabel.mas_right).offset(4);
}];
[self.minuteLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(self.firstHourLabel);
make.width.mas_equalTo(20);
make.left.mas_equalTo(self.secondMinuteLabel.mas_right);
}];
[self.firstSecondLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.centerY.mas_equalTo(self.firstHourLabel);
make.left.mas_equalTo(self.minuteLabel.mas_right).offset(0);
}];
[self.secondSecondabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.centerY.mas_equalTo(self.firstHourLabel);
make.left.mas_equalTo(self.firstSecondLabel.mas_right).offset(4);
}];
[self.secondsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(self.firstHourLabel);
make.width.mas_equalTo(20);
make.left.mas_equalTo(self.secondSecondabel.mas_right);
}];
}
#pragma mark - Getters And Setters
- (void)setNextRemaining:(int)nextRemaining {
_nextRemaining = nextRemaining;
if (_nextRemaining > 0) {
int seconds = _nextRemaining % 60;
int minutes = (_nextRemaining / 60) % 60;
int hours = _nextRemaining / 3600;
NSString * hour = [NSString stringWithFormat:@"%02d", hours];
NSString * minute = [NSString stringWithFormat:@"%02d", minutes];
NSString * second = [NSString stringWithFormat:@"%02d", seconds];
if (second.length > 1){
self.firstSecondLabel.text = [second substringWithRange:NSMakeRange(0, second.length -1)];
self.secondSecondabel.text = [second substringFromIndex:second.length - 1];
}
if (minute.length > 1){
self.firstMinuteLabel.text = [second substringWithRange:NSMakeRange(0, second.length -1)];
self.secondMinuteLabel.text = [second substringFromIndex:second.length - 1];
}
if (hour.length > 1){
self.firstHourLabel.text = [second substringWithRange:NSMakeRange(0, second.length -1)];
self.secondHourLabel.text = [second substringFromIndex:second.length - 1];
}
}
}
- (UILabel *)firstHourLabel {
if (!_firstHourLabel) {
_firstHourLabel = [[UILabel alloc] init];
_firstHourLabel.font = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium];
_firstHourLabel.textColor = [ThemeColor mainTextColor];
_firstHourLabel.backgroundColor = [ThemeColor colorWithHexString:@"#E8EAF3"];
_firstHourLabel.textAlignment = NSTextAlignmentCenter;
_firstHourLabel.layer.masksToBounds = YES;
_firstHourLabel.layer.cornerRadius = 4;
_firstHourLabel.text = @"0";
}
return _firstHourLabel;
}
- (UILabel *)secondHourLabel {
if (!_secondHourLabel) {
_secondHourLabel = [[UILabel alloc] init];
_secondHourLabel.font = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium];
_secondHourLabel.textColor = [ThemeColor mainTextColor];
_secondHourLabel.backgroundColor = [ThemeColor colorWithHexString:@"#E8EAF3"];
_secondHourLabel.textAlignment = NSTextAlignmentCenter;
_secondHourLabel.layer.masksToBounds = YES;
_secondHourLabel.layer.cornerRadius = 4;
_secondHourLabel.text = @"0";
}
return _secondHourLabel;
}
- (UILabel *)hourLabel {
if (!_hourLabel) {
_hourLabel = [[UILabel alloc] init];
_hourLabel.font = [UIFont systemFontOfSize:12];
_hourLabel.textColor = [ThemeColor mainTextColor];
_hourLabel.text = @"";
}
return _hourLabel;
}
- (UILabel *)firstMinuteLabel {
if (!_firstMinuteLabel) {
_firstMinuteLabel = [[UILabel alloc] init];
_firstMinuteLabel.font = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium];
_firstMinuteLabel.textColor = [ThemeColor mainTextColor];
_firstMinuteLabel.backgroundColor = [ThemeColor colorWithHexString:@"#E8EAF3"];
_firstMinuteLabel.textAlignment = NSTextAlignmentCenter;
_firstMinuteLabel.layer.masksToBounds = YES;
_firstMinuteLabel.layer.cornerRadius = 4;
_firstMinuteLabel.text = @"0";
}
return _firstMinuteLabel;
}
- (UILabel *)secondMinuteLabel {
if (!_secondMinuteLabel) {
_secondMinuteLabel = [[UILabel alloc] init];
_secondMinuteLabel.font = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium];
_secondMinuteLabel.textColor = [ThemeColor mainTextColor];
_secondMinuteLabel.backgroundColor = [ThemeColor colorWithHexString:@"#E8EAF3"];
_secondMinuteLabel.textAlignment = NSTextAlignmentCenter;
_secondMinuteLabel.layer.masksToBounds = YES;
_secondMinuteLabel.layer.cornerRadius = 4;
_secondMinuteLabel.text = @"0";
}
return _secondMinuteLabel;
}
- (UILabel *)minuteLabel {
if (!_minuteLabel) {
_minuteLabel = [[UILabel alloc] init];
_minuteLabel.font = [UIFont systemFontOfSize:12];
_minuteLabel.textColor = [ThemeColor mainTextColor];
_minuteLabel.text = @"";
}
return _minuteLabel;
}
- (UILabel *)firstSecondLabel {
if (!_firstSecondLabel) {
_firstSecondLabel = [[UILabel alloc] init];
_firstSecondLabel.font = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium];
_firstSecondLabel.textColor = [ThemeColor mainTextColor];
_firstSecondLabel.backgroundColor = [ThemeColor colorWithHexString:@"#E8EAF3"];
_firstSecondLabel.textAlignment = NSTextAlignmentCenter;
_firstSecondLabel.layer.masksToBounds = YES;
_firstSecondLabel.layer.cornerRadius = 4;
_firstSecondLabel.text = @"0";
}
return _firstSecondLabel;
}
- (UILabel *)secondSecondabel {
if (!_secondSecondabel) {
_secondSecondabel = [[UILabel alloc] init];
_secondSecondabel.font = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium];
_secondSecondabel.textColor = [ThemeColor mainTextColor];
_secondSecondabel.backgroundColor = [ThemeColor colorWithHexString:@"#E8EAF3"];
_secondSecondabel.textAlignment = NSTextAlignmentCenter;
_secondSecondabel.layer.masksToBounds = YES;
_secondSecondabel.layer.cornerRadius = 4;
_secondSecondabel.text = @"0";
}
return _secondSecondabel;
}
- (UILabel *)secondsLabel {
if (!_secondsLabel) {
_secondsLabel = [[UILabel alloc] init];
_secondsLabel.font = [UIFont systemFontOfSize:16];
_secondsLabel.textColor = [ThemeColor mainTextColor];
_secondsLabel.text = @"";
}
return _secondsLabel;
}
@end