动态详情
This commit is contained in:
267
xplan-ios/Main/Monents/View/Cell/XPMonentsCommentTableViewCell.m
Normal file
267
xplan-ios/Main/Monents/View/Cell/XPMonentsCommentTableViewCell.m
Normal file
@@ -0,0 +1,267 @@
|
||||
//
|
||||
// XPMonentsCommentTableViewCell.m
|
||||
// xplan-ios
|
||||
//
|
||||
// Created by 冯硕 on 2022/6/22.
|
||||
//
|
||||
|
||||
#import "XPMonentsCommentTableViewCell.h"
|
||||
///Third
|
||||
#import <Masonry/Masonry.h>
|
||||
///Tool
|
||||
#import "NetImageView.h"
|
||||
#import "ThemeColor.h"
|
||||
#import "XPMonentsLayoutConfig.h"
|
||||
///Model
|
||||
#import "MonentsCommentModel.h"
|
||||
///View
|
||||
#import "XPMonentsReplyTableViewCell.h"
|
||||
#import "XPMonentsReplyMoreTableViewCell.h"
|
||||
|
||||
@interface XPMonentsCommentTableViewCell ()<UITableViewDelegate, UITableViewDataSource>
|
||||
///容器
|
||||
@property (nonatomic,strong) UIStackView *stackView;
|
||||
///评论者
|
||||
@property (nonatomic,strong) UIView * commentUserView;
|
||||
///评论者的头像
|
||||
@property (nonatomic,strong) NetImageView *commentAvatarView;
|
||||
///评论者的昵称
|
||||
@property (nonatomic,strong) UILabel *commentNickLabel;
|
||||
///评论的内容
|
||||
@property (nonatomic,strong) UILabel *commentLabel;
|
||||
///时间
|
||||
@property (nonatomic,strong) UILabel *commentDateLabel;
|
||||
///列表
|
||||
@property (nonatomic,strong) UITableView *tableView;
|
||||
///容器
|
||||
@property (nonatomic,strong) UIView * lineContainerView;
|
||||
///分割线
|
||||
@property (nonatomic,strong) UIView * lineView;
|
||||
///数据源
|
||||
@property (nonatomic,strong) NSArray *datasource;
|
||||
@end
|
||||
|
||||
@implementation XPMonentsCommentTableViewCell
|
||||
|
||||
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
|
||||
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
|
||||
[self initSubViews];
|
||||
[self initSubViewConstraints];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
#pragma mark - Private Method
|
||||
|
||||
- (void)initSubViews {
|
||||
self.backgroundColor = [ThemeColor appCellBackgroundColor];
|
||||
self.selectionStyle = UITableViewCellSelectionStyleNone;
|
||||
[self.contentView addSubview:self.stackView];
|
||||
[self.stackView addArrangedSubview:self.commentUserView];
|
||||
[self.stackView addArrangedSubview:self.tableView];
|
||||
[self.stackView addArrangedSubview:self.lineContainerView];
|
||||
|
||||
[self.lineContainerView addSubview:self.lineView];
|
||||
|
||||
[self.commentUserView addSubview:self.commentAvatarView];
|
||||
[self.commentUserView addSubview:self.commentNickLabel];
|
||||
[self.commentUserView addSubview:self.commentLabel];
|
||||
[self.commentUserView addSubview:self.commentDateLabel];
|
||||
}
|
||||
|
||||
- (void)initSubViewConstraints {
|
||||
[self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.right.left.mas_equalTo(self.contentView).inset(15);
|
||||
make.top.bottom.mas_equalTo(self.contentView);
|
||||
}];
|
||||
|
||||
[self.lineContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.height.mas_equalTo(1);
|
||||
}];
|
||||
|
||||
|
||||
[self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(self.commentNickLabel);
|
||||
make.top.bottom.right.mas_equalTo(self.lineContainerView);
|
||||
}];
|
||||
|
||||
[self.commentAvatarView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.size.mas_equalTo(CGSizeMake(KMONENTS_COMMENT_AVATAR_WIDTH, KMONENTS_COMMENT_AVATAR_WIDTH));
|
||||
make.left.mas_equalTo(self.commentUserView);
|
||||
make.top.mas_equalTo(self.commentUserView).offset(10);
|
||||
}];
|
||||
|
||||
[self.commentNickLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(self.commentAvatarView.mas_right).offset(10);
|
||||
make.top.mas_equalTo(self.commentUserView).offset(10);
|
||||
make.height.mas_equalTo(15);
|
||||
make.right.mas_lessThanOrEqualTo(self.commentDateLabel.mas_left).offset(-10);
|
||||
}];
|
||||
|
||||
[self.commentDateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.right.mas_equalTo(self.commentUserView);
|
||||
make.centerY.mas_equalTo(self.commentNickLabel);
|
||||
}];
|
||||
|
||||
[self.commentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(self.commentNickLabel);
|
||||
make.top.mas_equalTo(self.commentNickLabel.mas_bottom).offset(10);
|
||||
make.right.mas_equalTo(self.commentUserView).offset(-kMONENTS_COMMENT_RIGHT_PADDING);
|
||||
}];
|
||||
}
|
||||
|
||||
#pragma mark - UITableViewDelegate And UITableViewDataSource
|
||||
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
|
||||
return 2;
|
||||
}
|
||||
|
||||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
||||
if (section == 0) {
|
||||
return self.datasource.count;
|
||||
}
|
||||
return self.commentInfo.replyInfo.leftCount > 0 ? 1 : 0;
|
||||
}
|
||||
|
||||
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
if (indexPath.section == 0) {
|
||||
MonentsReplyModel * replayinfo = [self.datasource objectAtIndex:indexPath.row];
|
||||
return replayinfo.replyRowHeight;
|
||||
}
|
||||
return 44;
|
||||
}
|
||||
|
||||
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
if (indexPath.section == 0) {
|
||||
XPMonentsReplyTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPMonentsReplyTableViewCell class])];
|
||||
cell.replyInfo = [self.datasource objectAtIndex:indexPath.row];
|
||||
return cell;
|
||||
}
|
||||
|
||||
XPMonentsReplyMoreTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPMonentsReplyMoreTableViewCell class])];
|
||||
cell.leftCount = self.commentInfo.replyInfo.leftCount;
|
||||
return cell;
|
||||
|
||||
}
|
||||
|
||||
#pragma mark - Getters And Setters
|
||||
- (void)setCommentInfo:(MonentsCommentModel *)commentInfo {
|
||||
_commentInfo = commentInfo;
|
||||
if (_commentInfo) {
|
||||
self.commentAvatarView.imageUrl = _commentInfo.avatar;
|
||||
NSString * nick = _commentInfo.nick;
|
||||
if (nick.length > 8) {
|
||||
nick = [nick substringToIndex:8];
|
||||
}
|
||||
self.commentLabel.text = _commentInfo.content;
|
||||
self.commentNickLabel.text = nick;
|
||||
self.commentDateLabel.text = _commentInfo.publishTime;
|
||||
self.tableView.hidden = _commentInfo.replyInfo.replyList.count <=0;
|
||||
self.datasource = _commentInfo.replyInfo.replyList;
|
||||
[self.tableView reloadData];
|
||||
if (_commentInfo.replyInfo.replyList.count > 0) {
|
||||
NSString * content = _commentInfo.content.length > 0 ? _commentInfo.content : @"";
|
||||
CGFloat commentHeight = [content boundingRectWithSize:CGSizeMake(KMONENTS_COMMENT_MAX_WIDTH, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingTruncatesLastVisibleLine attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil].size.height + 5;
|
||||
commentHeight = MAX(commentHeight, 15);
|
||||
[self.commentUserView mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.height.mas_equalTo(commentHeight + 10 + 15 + 10);
|
||||
}];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
- (UIStackView *)stackView {
|
||||
if (!_stackView) {
|
||||
_stackView = [[UIStackView alloc] init];
|
||||
_stackView.axis = UILayoutConstraintAxisVertical;
|
||||
_stackView.distribution = UIStackViewDistributionFill;
|
||||
_stackView.alignment = UIStackViewAlignmentFill;
|
||||
_stackView.spacing = 10;
|
||||
}
|
||||
return _stackView;
|
||||
}
|
||||
|
||||
- (UIView *)commentUserView {
|
||||
if (!_commentUserView) {
|
||||
_commentUserView = [[UIView alloc] init];
|
||||
_commentUserView.backgroundColor = [UIColor clearColor];
|
||||
}
|
||||
return _commentUserView;
|
||||
}
|
||||
|
||||
- (NetImageView *)commentAvatarView {
|
||||
if (!_commentAvatarView) {
|
||||
NetImageConfig * config = [[NetImageConfig alloc]init];
|
||||
config.imageType = ImageTypeUserIcon;
|
||||
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
|
||||
_commentAvatarView = [[NetImageView alloc] initWithConfig:config];
|
||||
_commentAvatarView.layer.masksToBounds = YES;
|
||||
_commentAvatarView.layer.cornerRadius = 45/2.0;
|
||||
}
|
||||
return _commentAvatarView;
|
||||
}
|
||||
|
||||
- (UILabel *)commentNickLabel {
|
||||
if (!_commentNickLabel) {
|
||||
_commentNickLabel = [[UILabel alloc] init];
|
||||
_commentNickLabel.font = [UIFont systemFontOfSize:15 weight:UIFontWeightMedium];
|
||||
_commentNickLabel.textColor = [ThemeColor mainTextColor];
|
||||
[_commentNickLabel sizeToFit];
|
||||
}
|
||||
return _commentNickLabel;
|
||||
}
|
||||
|
||||
- (UILabel *)commentLabel {
|
||||
if (!_commentLabel) {
|
||||
_commentLabel = [[UILabel alloc] init];
|
||||
_commentLabel.font = [UIFont systemFontOfSize:15];
|
||||
_commentLabel.numberOfLines = 0;
|
||||
_commentLabel.textColor = [ThemeColor secondTextColor];
|
||||
}
|
||||
return _commentLabel;
|
||||
}
|
||||
|
||||
- (UILabel *)commentDateLabel {
|
||||
if (!_commentDateLabel) {
|
||||
_commentDateLabel = [[UILabel alloc] init];
|
||||
_commentDateLabel.font = [UIFont systemFontOfSize:12];
|
||||
_commentDateLabel.textColor = [ThemeColor textThirdColor];
|
||||
}
|
||||
return _commentDateLabel;
|
||||
}
|
||||
|
||||
- (UITableView *)tableView {
|
||||
if (!_tableView) {
|
||||
_tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
|
||||
_tableView.delegate = self;
|
||||
_tableView.dataSource = self;
|
||||
_tableView.tableFooterView = [UIView new];
|
||||
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
|
||||
_tableView.backgroundColor = [UIColor clearColor];
|
||||
_tableView.scrollEnabled = NO;
|
||||
if (@available(iOS 11.0, *)) {
|
||||
_tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
|
||||
}
|
||||
[_tableView registerClass:[XPMonentsReplyTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPMonentsReplyTableViewCell class])];
|
||||
[_tableView registerClass:[XPMonentsReplyMoreTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPMonentsReplyMoreTableViewCell class])];
|
||||
}
|
||||
return _tableView;
|
||||
}
|
||||
|
||||
- (UIView *)lineView {
|
||||
if (!_lineView) {
|
||||
_lineView = [[UIView alloc] init];
|
||||
_lineView.backgroundColor = [ThemeColor dividerColor];
|
||||
}
|
||||
return _lineView;
|
||||
}
|
||||
|
||||
- (UIView *)lineContainerView {
|
||||
if (!_lineContainerView) {
|
||||
_lineContainerView = [[UIView alloc] init];
|
||||
_lineContainerView.backgroundColor = [UIColor clearColor];
|
||||
}
|
||||
return _lineContainerView;
|
||||
}
|
||||
|
||||
@end
|
Reference in New Issue
Block a user