Files
featherVoice/QXLive/Dynamic(语圈)/View/详情/QXDynamicCommentCell.m
2025-08-08 10:49:36 +08:00

62 lines
2.3 KiB
Objective-C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// QXDynamicCommentCell.m
// QXLive
//
// Created by 启星 on 2025/6/4.
//
#import "QXDynamicCommentCell.h"
@implementation QXDynamicCommentCell
+(instancetype)cellWithTableView:(UITableView *)tableView{
static NSString *cellId = @"QXDynamicCommentCell";
QXDynamicCommentCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
if (!cell) {
cell = [[NSBundle mainBundle] loadNibNamed:cellId owner:nil options:nil].lastObject;
cell.backgroundColor = [UIColor clearColor];
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:cell action:@selector(handleLongPress:)];
[cell addGestureRecognizer:longPress];
}
return cell;
}
-(void)setModel:(QXDynamicCommentListModel *)model{
_model = model;
NSString *commentUser = @"";
if (model.reply_to_user.length == 0) {
commentUser = [NSString stringWithFormat:@"%@",model.nickname];
}else{
commentUser = [NSString localizedStringWithFormat:QXText(@"%@ 回复 %@"),model.nickname,model.reply_to_user];
}
NSString* content = [NSString stringWithFormat:@"%@%@",commentUser,model.content];
NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:content];
[attr yy_setColor:RGB16(0x999999) range:[content rangeOfString:model.content]];
[attr yy_setColor:RGB16(0x333333) range:[content rangeOfString:commentUser]];
self.commentLabel.attributedText = attr;
NSDate *date = [NSDate dateWithTimeIntervalSince1970:model.createtime.longLongValue]; //此处根据项目需求,选择是否除以1000 , 如果时间戳精确到秒则去掉1000
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";
NSString*time = [formatter stringFromDate:date];
self.timeLabel.text = time;
}
-(void)handleLongPress:(UILongPressGestureRecognizer *)gesture{
if (gesture.state == UIGestureRecognizerStateBegan) {
if (self.longPressBlock) {
self.longPressBlock(self.model);
}
}
}
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end