// // KBChatTimeCell.m // keyBoard // // Created by Kiro on 2026/1/23. // #import "KBChatTimeCell.h" #import "KBAiChatMessage.h" #import @interface KBChatTimeCell () @property (nonatomic, strong) UILabel *timeLabel; @end @implementation KBChatTimeCell - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { self.backgroundColor = [UIColor clearColor]; self.selectionStyle = UITableViewCellSelectionStyleNone; [self setupUI]; } return self; } - (void)setupUI { // 时间标签 self.timeLabel = [[UILabel alloc] init]; self.timeLabel.font = [UIFont systemFontOfSize:12]; self.timeLabel.textColor = [UIColor secondaryLabelColor]; self.timeLabel.textAlignment = NSTextAlignmentCenter; [self.contentView addSubview:self.timeLabel]; // 布局约束 [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.contentView).offset(1); make.bottom.equalTo(self.contentView).offset(-1); make.centerX.equalTo(self.contentView); }]; } - (void)configureWithMessage:(KBAiChatMessage *)message { self.timeLabel.text = [self formatTimestamp:message.timestamp]; } /// 格式化时间戳 - (NSString *)formatTimestamp:(NSDate *)timestamp { NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; NSCalendar *calendar = [NSCalendar currentCalendar]; if ([calendar isDateInToday:timestamp]) { // 今天:显示时间 formatter.dateFormat = @"HH:mm"; } else if ([calendar isDateInYesterday:timestamp]) { // 昨天 formatter.dateFormat = @"'昨天' HH:mm"; } else { // 其他:显示日期 + 时间 formatter.dateFormat = @"MM月dd日 HH:mm"; } return [formatter stringFromDate:timestamp]; } @end