| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- //
- // MORankCountdownTopView.m
- // MiMoLive
- //
- // Created by SuperC on 2025/9/12.
- //
- #import "MORankCountdownTopView.h"
- @interface MORankCountdownTopView ()
- @property (nonatomic, strong) UILabel *countDownLab;
- @end
- @implementation MORankCountdownTopView
- - (instancetype)init {
- if (self = [super init] ) {
- [self setupUI];
- }
- return self;
- }
- - (instancetype)initWithFrame:(CGRect)frame{
- self = [super initWithFrame:frame];
- if (self){
- [self setupUI];
- }
- return self;
- }
- - (void)setupUI{
- [self addSubview:self.countDownLab];
- [self.countDownLab mas_makeConstraints:^(MASConstraintMaker *make) {
- make.height.equalTo(@24.0);
- make.centerX.equalTo(self);
- make.width.equalTo(@166.0);
- make.centerY.equalTo(self);
- }];
- }
- - (UILabel *)countDownLab{
- if(!_countDownLab){
- _countDownLab = [[UILabel alloc] init];
- _countDownLab.backgroundColor = [MOTools colorWithHexString:@"#F3F4FA" alpha:1.0];
- _countDownLab.layer.cornerRadius = 12.0;
- _countDownLab.layer.masksToBounds = YES;
- _countDownLab.textColor = [MOTools colorWithHexString:@"#5C5E66" alpha:1.0];
- _countDownLab.font = [MOTextTools poppinsMediumFont:12.0];
- _countDownLab.text = @"Countdown: 00d 00h 00m";
- _countDownLab.textAlignment = NSTextAlignmentCenter;
- }
- return _countDownLab;
- }
- - (void)setEndTime:(double)endTime{
- _endTime = endTime;
-
- if(endTime <= 0){
- return;
- }
-
- [self toUpdateTheCountDownLab];
- }
- - (void)toUpdateTheCountDownLab{
-
- if(self.endTime <= 0){
- return;
- }
-
- NSTimeInterval currentTime = [[NSDate date] timeIntervalSince1970];
- NSTimeInterval interval = self.endTime / 1000.0 - currentTime;
-
- NSDateComponents *components = [[NSCalendar currentCalendar]
- components:(NSCalendarUnitSecond | NSCalendarUnitHour | NSCalendarUnitMinute)
- fromDate:[NSDate dateWithTimeIntervalSince1970:0]
- toDate:[NSDate dateWithTimeIntervalSince1970:interval]
- options:0];
-
- if(interval > 0){
-
- NSString *result = [NSString stringWithFormat:@"%02ldm %02lds",
- (long)components.minute,
- (long)components.second];
-
- NSString *timeStr = [NSString stringWithFormat:NSLocalString(@"C60011"),result];
-
- //富文本 宽度
- NSAttributedString *contentStr = [MOTextTools base_colorObjectStringWith:timeStr AndNameStr:result AndBaseColor:kBaseTextColor_2 AndNameColor:kBaseTextColor_1];
- self.countDownLab.attributedText = contentStr;
-
- CGFloat labWidth = [MOTools getWidthWithString:timeStr font:[MOTextTools poppinsMediumFont:12.0]] + 20.0;
- [self.countDownLab mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.width.equalTo(@(labWidth));
- make.height.equalTo(@24.0);
- make.centerX.equalTo(self);
- make.centerY.equalTo(self);
- }];
- }
- else{
- self.timeEndBlock ? self.timeEndBlock() : nil;
- }
- }
- - (void)oneSecondPassed{
- [self toUpdateTheCountDownLab];
- }
- @end
|