Files
fanyin-ios/QXLive/Dynamic(语圈)/View/详情/QXDynamicCommentHeaderView.m
2025-08-12 14:27:12 +08:00

129 lines
5.1 KiB
Objective-C

//
// QXDynamicCommentHeaderView.m
// QXLive
//
// Created by 启星 on 2025/6/4.
//
#import "QXDynamicCommentHeaderView.h"
@interface QXDynamicCommentHeaderView()
@property (nonatomic,strong)UIImageView *headerImageView;
@property (nonatomic,strong)UILabel *nameLabel;
@property (nonatomic,strong)UILabel *contentLabel;
@property (nonatomic,strong)UILabel *timeLabel;
@property (nonatomic,strong)UIButton *replyBtn;
@property (nonatomic,strong)UIButton *deleteBtn;
@end
@implementation QXDynamicCommentHeaderView
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self initSubviews];
}
return self;
}
-(void)initSubviews{
self.headerImageView = [[UIImageView alloc] init];
self.headerImageView.contentMode = UIViewContentModeScaleAspectFill;
[self.headerImageView addRoundedCornersWithRadius:20];
[self addSubview:self.headerImageView];
[self.headerImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(16);
make.height.width.mas_equalTo(40);
make.top.mas_equalTo(12);
}];
self.nameLabel = [[UILabel alloc] init];
self.nameLabel.textColor = [UIColor blackColor];
self.nameLabel.font = [UIFont systemFontOfSize:12];
[self addSubview:self.nameLabel];
[self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.headerImageView.mas_right).offset(7);
make.height.mas_equalTo(16);
make.top.mas_equalTo(12);
make.right.mas_equalTo(-16);
}];
self.contentLabel = [[UILabel alloc] init];
self.contentLabel.textColor = [UIColor blackColor];
self.contentLabel.font = [UIFont systemFontOfSize:14];
self.contentLabel.numberOfLines = 0;
[self addSubview:self.contentLabel];
[self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.nameLabel);
make.top.equalTo(self.nameLabel.mas_bottom).offset(7);
make.right.mas_equalTo(-16);
}];
self.timeLabel = [[UILabel alloc] init];
self.timeLabel.textColor = RGB16(0x939393);
self.timeLabel.font = [UIFont systemFontOfSize:12];
[self addSubview:self.timeLabel];
[self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.nameLabel);
make.height.mas_equalTo(20);
make.top.equalTo(self.contentLabel.mas_bottom).offset(2);
}];
self.replyBtn = [[UIButton alloc] init];
[self.replyBtn setTitle:QXText(@"回复") forState:(UIControlStateNormal)];
self.replyBtn.titleLabel.font = [UIFont systemFontOfSize:12];
[self.replyBtn setTitleColor:RGB16(0x939393) forState:(UIControlStateNormal)];
[self.replyBtn addRoundedCornersWithRadius:5];
self.replyBtn.backgroundColor = RGB16(0xF5F5F5);
[self.replyBtn addTarget:self action:@selector(replyAction) forControlEvents:(UIControlEventTouchUpInside)];
[self addSubview:self.replyBtn];
[self.replyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.timeLabel.mas_right).offset(12);
make.height.mas_equalTo(20);
make.width.mas_equalTo(ScaleWidth(38));
make.centerY.equalTo(self.timeLabel);
}];
self.deleteBtn = [[UIButton alloc] init];
[self.deleteBtn setTitle:QXText(@"删除") forState:(UIControlStateNormal)];
self.deleteBtn.titleLabel.font = [UIFont systemFontOfSize:12];
[self.deleteBtn setTitleColor:RGB16(0x939393) forState:(UIControlStateNormal)];
[self.deleteBtn addTarget:self action:@selector(deleteAction) forControlEvents:(UIControlEventTouchUpInside)];
[self addSubview:self.deleteBtn];
[self.deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.replyBtn.mas_right).offset(6);
make.height.mas_equalTo(20);
make.width.mas_equalTo(ScaleWidth(38));
make.centerY.equalTo(self.timeLabel);
}];
}
-(void)setModel:(QXDynamicCommentListModel *)model{
_model = model;
[self.headerImageView sd_setImageWithURL:[NSURL URLWithString:model.avatar] placeholderImage:[UIImage imageNamed:@"user_header_placehoulder"]];
self.nameLabel.text = model.nickname;
self.contentLabel.text = model.content;
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;
if ([model.user_id isEqualToString:[QXGlobal shareGlobal].loginModel.user_id]) {
self.deleteBtn.hidden = NO;
}else{
self.deleteBtn.hidden = YES;
}
}
-(void)replyAction{
if (self.delegate && [self.delegate respondsToSelector:@selector(didClickReplyComment:)]) {
[self.delegate didClickReplyComment:self.model];
}
}
-(void)deleteAction{
if (self.delegate && [self.delegate respondsToSelector:@selector(didClickDeleteComment:)]) {
[self.delegate didClickDeleteComment:self.model];
}
}
@end