This commit is contained in:
2026-01-23 21:51:37 +08:00
parent 6ad9783bcb
commit 77fd46aa34
26 changed files with 3681 additions and 199 deletions

View File

@@ -0,0 +1,70 @@
//
// KBChatTimeCell.m
// keyBoard
//
// Created by Kiro on 2026/1/23.
//
#import "KBChatTimeCell.h"
#import "KBAiChatMessage.h"
#import <Masonry/Masonry.h>
@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(8);
make.bottom.equalTo(self.contentView).offset(-8);
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