74 lines
2.5 KiB
Objective-C
74 lines
2.5 KiB
Objective-C
//
|
|
// NotiCenterTableViewCell.m
|
|
// ShenQi
|
|
//
|
|
// Created by twotutoo on 2025/1/11.
|
|
//
|
|
|
|
#import "NotiCenterTableViewCell.h"
|
|
|
|
#import "MacroDefine.h"
|
|
|
|
@implementation NotiCenterTableViewCell
|
|
|
|
- (void)awakeFromNib {
|
|
[super awakeFromNib];
|
|
|
|
[self setSelectionStyle:(UITableViewCellSelectionStyleNone)];
|
|
self.contentView.backgroundColor = UIColorFromRGB(0xFAFAFA);
|
|
self.typeLabel.layer.cornerRadius = 4.f;
|
|
self.typeLabel.layer.masksToBounds = YES;
|
|
}
|
|
|
|
-(void)setList:(PushRecordList *)list
|
|
{
|
|
_list = list;
|
|
|
|
if (self.list.type == 1) {
|
|
self.typeLabel.text = @"Text";
|
|
self.mainView.backgroundColor = UIColorFromRGB(0xACDFEE);
|
|
}else if (self.list.type == 2) {
|
|
self.typeLabel.text = @"Image";
|
|
self.mainView.backgroundColor = UIColorFromRGB(0xBDDDB7);
|
|
}else if (self.list.type == 3) {
|
|
self.typeLabel.text = @"Jump link";
|
|
self.mainView.backgroundColor = UIColorFromRGB(0xC3B5D0);
|
|
}
|
|
UIFont *textFont = [UIFont boldSystemFontOfSize:15];
|
|
CGFloat width = [self.typeLabel.text boundingRectWithSize:CGSizeMake(MAXFLOAT, 30) options:NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName: textFont} context:nil].size.width;
|
|
self.widthConstraint.constant = width+10;
|
|
self.dateLabel.text = self.list.createTime;
|
|
self.titleLabel.text = self.list.title;
|
|
|
|
double minutesDiff = [self minutesDifferenceFromTimeString:self.list.createTime withFormat:@"yyyy-MM-dd HH:mm:ss"];
|
|
[self.pvLab setTitle:[NSString stringWithFormat:@" %.0f",1000+minutesDiff] forState:0];
|
|
|
|
}
|
|
|
|
// 计算时间字符串与当前时间的分钟差
|
|
- (double)minutesDifferenceFromTimeString:(NSString *)timeString withFormat:(NSString *)dateFormat {
|
|
// 1. 创建日期格式化器
|
|
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
|
|
[dateFormatter setDateFormat:dateFormat]; // 例如: @"yyyy-MM-dd HH:mm:ss"
|
|
|
|
// 2. 将时间字符串转换为 NSDate
|
|
NSDate *targetDate = [dateFormatter dateFromString:timeString];
|
|
if (!targetDate) {
|
|
NSLog(@"时间字符串格式错误!");
|
|
return 0;
|
|
}
|
|
|
|
// 3. 获取当前时间
|
|
NSDate *currentDate = [NSDate date];
|
|
|
|
// 4. 计算时间差(秒)
|
|
NSTimeInterval timeInterval = [currentDate timeIntervalSinceDate:targetDate];
|
|
|
|
// 5. 转换为分钟(绝对值,避免负值)
|
|
double minutes = fabs(timeInterval / 60.0);
|
|
|
|
return minutes;
|
|
}
|
|
|
|
@end
|