You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
185 lines
7.8 KiB
185 lines
7.8 KiB
4 years ago
|
//
|
||
|
// TFCommentsViewCell.m
|
||
|
// TFReader
|
||
|
//
|
||
|
// Created by 谢腾飞 on 2020/12/13.
|
||
|
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
|
||
|
//
|
||
|
|
||
|
#import "TFCommentsViewCell.h"
|
||
|
|
||
|
@interface TFCommentsViewCell ()
|
||
|
|
||
|
@property (nonatomic ,strong) UIImageView *avatarView; // 头像
|
||
|
@property (nonatomic ,strong) UILabel *nicknameLabel; // 昵称
|
||
|
@property (nonatomic ,strong) UILabel *commentLabel; // 评论
|
||
|
@property (nonatomic ,strong) YYLabel *replyCommentLabel; // 二级评论
|
||
|
@property (nonatomic ,strong) UILabel *timeLabel; // 发布时间
|
||
|
@property (nonatomic ,strong) UIImageView *vipView;
|
||
|
|
||
|
@end
|
||
|
|
||
|
@implementation TFCommentsViewCell
|
||
|
|
||
|
- (void)createSubviews
|
||
|
{
|
||
|
[super createSubviews];
|
||
|
|
||
|
// 头像
|
||
|
self.avatarView = [[UIImageView alloc] initWithCornerRadiusAdvance:35.0f / 2 rectCornerType:UIRectCornerAllCorners];
|
||
|
[self.contentView addSubview:self.avatarView];
|
||
|
|
||
|
[self.avatarView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.mas_equalTo(self.contentView.mas_left).with.offset(kMargin);
|
||
|
make.top.mas_equalTo(self.contentView.mas_top).with.offset(kHalfMargin);
|
||
|
make.width.height.mas_equalTo(35.0f);
|
||
|
}];
|
||
|
|
||
|
// 昵称
|
||
|
self.nicknameLabel = [[UILabel alloc] init];
|
||
|
self.nicknameLabel.textColor = kGrayTextDeepColor;
|
||
|
self.nicknameLabel.font = kFont13;
|
||
|
self.nicknameLabel.textAlignment = NSTextAlignmentLeft;
|
||
|
[self.contentView addSubview:self.nicknameLabel];
|
||
|
|
||
|
[self.nicknameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.mas_equalTo(self.avatarView.mas_right).with.offset(kHalfMargin);
|
||
|
make.top.mas_equalTo(self.avatarView.mas_top);
|
||
|
make.width.mas_equalTo(200);
|
||
|
make.height.mas_equalTo(self.avatarView.mas_height).multipliedBy(0.6);
|
||
|
}];
|
||
|
|
||
|
self.timeLabel = [[UILabel alloc] init];
|
||
|
self.timeLabel.textAlignment = NSTextAlignmentLeft;
|
||
|
self.timeLabel.font = kFont10;
|
||
|
self.timeLabel.textColor = kGrayTextColor;
|
||
|
[self.contentView addSubview:self.timeLabel];
|
||
|
|
||
|
[self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.mas_equalTo(self.nicknameLabel.mas_left);
|
||
|
make.bottom.mas_equalTo(self.avatarView.mas_bottom);
|
||
|
make.right.mas_equalTo(self.contentView.mas_right);
|
||
|
make.height.mas_equalTo(self.avatarView.mas_height).multipliedBy(0.4);
|
||
|
}];
|
||
|
|
||
|
self.vipView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"public_vip_select"]];
|
||
|
self.vipView.hidden = YES;
|
||
|
[self addSubview:self.vipView];
|
||
|
|
||
|
[self.vipView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.mas_equalTo(self.nicknameLabel.mas_right);
|
||
|
make.centerY.mas_equalTo(self.nicknameLabel.mas_centerY);
|
||
|
make.height.mas_equalTo(10);
|
||
|
make.width.mas_equalTo(kGeometricWidth(10, 138, 48));
|
||
|
}];
|
||
|
|
||
|
// 二级评论
|
||
|
self.replyCommentLabel = [[YYLabel alloc] init];
|
||
|
self.replyCommentLabel.textAlignment = NSTextAlignmentLeft;
|
||
|
self.replyCommentLabel.textColor = kGrayTextDeepColor;
|
||
|
self.replyCommentLabel.font = kFont13;
|
||
|
self.replyCommentLabel.backgroundColor = kGrayViewColor;
|
||
|
self.replyCommentLabel.numberOfLines = 0;
|
||
|
self.replyCommentLabel.textContainerInset = UIEdgeInsetsMake(6, 5, 4, 5);
|
||
|
[self.contentView addSubview:self.replyCommentLabel];
|
||
|
|
||
|
[self.replyCommentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.mas_equalTo(self.nicknameLabel.mas_left);
|
||
|
make.top.mas_equalTo(self.avatarView.mas_bottom);
|
||
|
make.right.mas_equalTo(self.contentView.mas_right).with.offset(- kMargin);
|
||
|
make.height.mas_equalTo(CGFLOAT_MIN);
|
||
|
}];
|
||
|
|
||
|
// 评论
|
||
|
self.commentLabel = [[UILabel alloc] init];
|
||
|
self.commentLabel.textAlignment = NSTextAlignmentLeft;
|
||
|
self.commentLabel.font = kMainFont;
|
||
|
self.commentLabel.numberOfLines = 0;
|
||
|
self.commentLabel.textColor = kBlackColor;
|
||
|
[self.contentView addSubview:self.commentLabel];
|
||
|
|
||
|
[self.commentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.mas_equalTo(self.nicknameLabel.mas_left);
|
||
|
make.right.mas_equalTo(self.contentView.mas_right).with.offset(- kMargin);
|
||
|
make.top.mas_equalTo(self.replyCommentLabel.mas_bottom).with.offset(kHalfMargin);
|
||
|
make.height.mas_equalTo(200);
|
||
|
make.bottom.mas_equalTo(self.contentView.mas_bottom).with.offset(- kHalfMargin).priorityLow();
|
||
|
}];
|
||
|
}
|
||
|
|
||
|
- (void)setIsPreview:(BOOL)isPreview lastRow:(BOOL)lastRow
|
||
|
{
|
||
|
if (isPreview && !lastRow) {
|
||
|
[self.lineView mas_remakeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.equalTo(self.commentLabel);
|
||
|
make.height.mas_equalTo(kCellLineHeight);
|
||
|
make.right.equalTo(self.contentView);
|
||
|
make.bottom.mas_equalTo(self.contentView.mas_bottom).with.offset(-kCellLineHeight);
|
||
|
}];
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (isPreview && lastRow) {
|
||
|
[self.lineView mas_remakeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.equalTo(self.avatarView);
|
||
|
make.height.mas_equalTo(kCellLineHeight);
|
||
|
make.right.equalTo(self.contentView);
|
||
|
make.bottom.mas_equalTo(self.contentView.mas_bottom).with.offset(-kCellLineHeight);
|
||
|
}];
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
- (void)setCommentModel:(TFCommentsListModel *)commentModel
|
||
|
{
|
||
|
if (!commentModel) return;
|
||
|
|
||
|
_commentModel = commentModel;
|
||
|
|
||
|
self.timeLabel.text = [NSString stringWithFormat:@"%@",commentModel.time?:@""];
|
||
|
self.commentLabel.text = [NSString stringWithFormat:@"%@",commentModel.content?:@""];
|
||
|
|
||
|
if (commentModel.reply_info.length > 0) {
|
||
|
CGFloat replyHeight = [TFViewHelper getDynamicHeightWithLabelFont:kFont11 labelWidth:(SCREEN_WIDTH - 2 * kMargin - 35.0f - kHalfMargin) labelText:commentModel.reply_info ? : @""];
|
||
|
NSString *replyInfo = [NSString stringWithFormat:@"%@",commentModel.reply_info ? : @""];
|
||
|
|
||
|
NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
|
||
|
style.lineSpacing = 3;
|
||
|
|
||
|
NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:replyInfo];
|
||
|
[attrString addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, replyInfo.length)];
|
||
|
[attrString addAttribute:NSFontAttributeName value:kFont11 range:NSMakeRange(0, replyInfo.length)];
|
||
|
|
||
|
self.replyCommentLabel.attributedText = attrString;
|
||
|
[self.replyCommentLabel mas_updateConstraints:^(MASConstraintMaker *make) {
|
||
|
make.top.mas_equalTo(self.avatarView.mas_bottom).with.offset(kHalfMargin);
|
||
|
make.height.mas_equalTo(replyHeight);
|
||
|
}];
|
||
|
} else {
|
||
|
self.replyCommentLabel.attributedText = [[NSMutableAttributedString alloc] initWithString:@""];
|
||
|
[self.replyCommentLabel mas_updateConstraints:^(MASConstraintMaker *make) {
|
||
|
make.top.mas_equalTo(self.avatarView.mas_bottom);
|
||
|
make.height.mas_equalTo(CGFLOAT_MIN);
|
||
|
}];
|
||
|
}
|
||
|
|
||
|
[self.commentLabel mas_updateConstraints:^(MASConstraintMaker *make) {
|
||
|
make.height.mas_equalTo([TFViewHelper getDynamicHeightWithLabelFont:self.commentLabel.font labelWidth:(SCREEN_WIDTH - 35.0f - 2 * kMargin) labelText:self.commentLabel.text] - kHalfMargin);
|
||
|
}];
|
||
|
|
||
|
[self.avatarView setImageWithURL:[NSURL URLWithString:commentModel.avatar?:@""] placeholder:HoldUserAvatar options:YYWebImageOptionSetImageWithFadeAnimation completion:nil];
|
||
|
|
||
|
self.nicknameLabel.text = [NSString stringWithFormat:@"%@",commentModel.nickname?:@""];
|
||
|
[self.nicknameLabel mas_updateConstraints:^(MASConstraintMaker *make) {
|
||
|
make.width.mas_equalTo([TFViewHelper getDynamicWidthWithLabel:self.nicknameLabel maxWidth:SCREEN_WIDTH - 35 - 2 * kMargin]);
|
||
|
}];
|
||
|
|
||
|
if (commentModel.is_vip == 1) {
|
||
|
self.vipView.hidden = NO;
|
||
|
} else {
|
||
|
self.vipView.hidden = YES;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@end
|