155 lines
4.5 KiB
Objective-C
155 lines
4.5 KiB
Objective-C
//
|
|
// XPMonentsReplyTableViewCell.m
|
|
// xplan-ios
|
|
//
|
|
// Created by 冯硕 on 2022/6/22.
|
|
//
|
|
|
|
#import "XPMonentsReplyTableViewCell.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
#import <YYText/YYLabel.h>
|
|
///Tool
|
|
#import "ThemeColor.h"
|
|
#import "NetImageView.h"
|
|
#import "XPMacro.h"
|
|
#import "XPMonentsLayoutConfig.h"
|
|
#import "NSString+Utils.h"
|
|
///Model
|
|
#import "MonentsCommentReplyModel.h"
|
|
|
|
@interface XPMonentsReplyTableViewCell ()
|
|
///头像
|
|
@property (nonatomic,strong) NetImageView *avatarImageView;
|
|
///自己的名字
|
|
@property (nonatomic,strong) UILabel *nickLabel;
|
|
///内容
|
|
@property (nonatomic,strong) YYLabel *contentLabel;
|
|
///时间
|
|
@property (nonatomic,strong) UILabel *dateLabel;
|
|
///分割线
|
|
@property (nonatomic,strong) UIView * lineView;
|
|
|
|
@end
|
|
|
|
@implementation XPMonentsReplyTableViewCell
|
|
|
|
|
|
- (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 = [UIColor clearColor];
|
|
self.selectionStyle = UITableViewCellSelectionStyleNone;
|
|
[self.contentView addSubview:self.avatarImageView];
|
|
[self.contentView addSubview:self.nickLabel];
|
|
[self.contentView addSubview:self.contentLabel];
|
|
[self.contentView addSubview:self.dateLabel];
|
|
[self.contentView addSubview:self.lineView];
|
|
}
|
|
|
|
- (void)initSubViewConstraints {
|
|
[self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.size.mas_equalTo(CGSizeMake(KMONENTS_COMMENT_REPLY_AVATAR_WIDTH, KMONENTS_COMMENT_REPLY_AVATAR_WIDTH));
|
|
make.top.mas_equalTo(self.contentView).offset(10);
|
|
make.left.mas_equalTo(self.contentView).offset(kMONENTS_COMMENT_REPLY_LEFT_PADDING);
|
|
}];
|
|
|
|
[self.nickLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(self.avatarImageView.mas_right).offset(kMONENTS_COMMENT_AVATAR_NICK_PADDING);
|
|
make.top.mas_equalTo(self.contentView).offset(10);
|
|
make.height.mas_equalTo(15);
|
|
make.right.mas_lessThanOrEqualTo(self.dateLabel).offset(-5);
|
|
}];
|
|
|
|
[self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(self.nickLabel);
|
|
make.top.mas_equalTo(self.nickLabel.mas_bottom).offset(10);
|
|
make.right.mas_equalTo(self.contentView).offset(-15);
|
|
}];
|
|
|
|
[self.dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.right.mas_equalTo(self.contentView).offset(-10);
|
|
make.centerY.mas_equalTo(self.nickLabel);
|
|
}];
|
|
|
|
[self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(self.nickLabel);
|
|
make.right.mas_equalTo(self.contentView).offset(-10);
|
|
make.height.mas_equalTo(0.5);
|
|
make.bottom.mas_equalTo(self.contentView);
|
|
}];
|
|
}
|
|
|
|
#pragma mark - Getters And Setters
|
|
- (void)setReplyInfo:(MonentsReplyModel *)replyInfo {
|
|
_replyInfo = replyInfo;
|
|
if (_replyInfo) {
|
|
self.avatarImageView.imageUrl = _replyInfo.avatar;
|
|
NSString * nick = _replyInfo.nick;
|
|
if (nick.length > 8) {
|
|
nick = [nick substringToIndex:8];
|
|
}
|
|
self.nickLabel.text = nick;
|
|
self.dateLabel.text = [NSString stringWithTimeStamp:_replyInfo.publishTime];
|
|
self.contentLabel.attributedText = _replyInfo.contentAttribute;
|
|
}
|
|
}
|
|
|
|
- (NetImageView *)avatarImageView {
|
|
if (!_avatarImageView) {
|
|
NetImageConfig * config = [[NetImageConfig alloc]init];
|
|
config.imageType = ImageTypeUserIcon;
|
|
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
|
|
_avatarImageView = [[NetImageView alloc] initWithConfig:config];
|
|
_avatarImageView.layer.masksToBounds = YES;
|
|
_avatarImageView.layer.cornerRadius = 30/2.0;
|
|
_avatarImageView.layer.borderColor = [ThemeColor appMainColor].CGColor;
|
|
}
|
|
return _avatarImageView;
|
|
}
|
|
|
|
- (UILabel *)nickLabel {
|
|
if (!_nickLabel) {
|
|
_nickLabel = [[UILabel alloc] init];
|
|
_nickLabel.font = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium];
|
|
_nickLabel.textColor = [ThemeColor mainTextColor];
|
|
}
|
|
return _nickLabel;
|
|
}
|
|
|
|
- (YYLabel *)contentLabel {
|
|
if (!_contentLabel) {
|
|
_contentLabel = [[YYLabel alloc] init];
|
|
_contentLabel.preferredMaxLayoutWidth = KMONENTS_COMMENT_REPLY_MAX_WIDTH;
|
|
_contentLabel.numberOfLines = 0;
|
|
}
|
|
return _contentLabel;
|
|
}
|
|
|
|
- (UILabel *)dateLabel {
|
|
if (!_dateLabel) {
|
|
_dateLabel = [[UILabel alloc] init];
|
|
_dateLabel.font = [UIFont systemFontOfSize:12];
|
|
_dateLabel.textColor = [ThemeColor textThirdColor];
|
|
}
|
|
return _dateLabel;
|
|
}
|
|
|
|
- (UIView *)lineView {
|
|
if (!_lineView) {
|
|
_lineView = [[UIView alloc] init];
|
|
_lineView.backgroundColor = [ThemeColor dividerColor];
|
|
}
|
|
return _lineView;
|
|
}
|
|
|
|
|
|
@end
|