185 lines
5.6 KiB
Objective-C
185 lines
5.6 KiB
Objective-C
//
|
|
// YMMonentsReplyTableViewCell.m
|
|
// YUMI
|
|
//
|
|
// Created by YUMI on 2022/6/22.
|
|
//
|
|
|
|
#import "XPMonentsReplyTableViewCell.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
|
|
///Tool
|
|
#import "DJDKMIMOMColor.h"
|
|
#import "NetImageView.h"
|
|
#import "YUMIMacroUitls.h"
|
|
#import "XPMonentsLayoutConfig.h"
|
|
#import "NSString+Utils.h"
|
|
#import "QEmotionHelper.h"
|
|
///Model
|
|
#import "MonentsCommentReplyModel.h"
|
|
|
|
@interface XPMonentsReplyTableViewCell ()
|
|
///头像
|
|
@property (nonatomic,strong) NetImageView *avatarImageView;
|
|
///自己的名字
|
|
@property (nonatomic,strong) UILabel *nickLabel;
|
|
///房主
|
|
@property (nonatomic,strong) UIImageView *ownerImageView;
|
|
///内容
|
|
@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.ownerImageView];
|
|
[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);
|
|
}];
|
|
|
|
[self.ownerImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.size.mas_equalTo(CGSizeMake(30, 15));
|
|
make.centerY.mas_equalTo(self.nickLabel);
|
|
make.left.mas_equalTo(self.nickLabel.mas_right).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 - Event Response
|
|
- (void)tapAvatarImage {
|
|
if (self.delegate && [self.delegate respondsToSelector:@selector(xPMonentsReplyTableViewCell:didClickAvatar:)]) {
|
|
[self.delegate xPMonentsReplyTableViewCell:self didClickAvatar:self.replyInfo];
|
|
}
|
|
}
|
|
|
|
#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.ownerImageView.hidden = !_replyInfo.landLordFlag;
|
|
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 = [DJDKMIMOMColor appMainColor].CGColor;
|
|
_avatarImageView.userInteractionEnabled = YES;
|
|
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAvatarImage)];
|
|
[_avatarImageView addGestureRecognizer:tap];
|
|
}
|
|
return _avatarImageView;
|
|
}
|
|
|
|
- (UILabel *)nickLabel {
|
|
if (!_nickLabel) {
|
|
_nickLabel = [[UILabel alloc] init];
|
|
_nickLabel.font = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium];
|
|
_nickLabel.textColor = [DJDKMIMOMColor 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 = [DJDKMIMOMColor textThirdColor];
|
|
}
|
|
return _dateLabel;
|
|
}
|
|
|
|
- (UIView *)lineView {
|
|
if (!_lineView) {
|
|
_lineView = [[UIView alloc] init];
|
|
_lineView.backgroundColor = [DJDKMIMOMColor dividerColor];
|
|
}
|
|
return _lineView;
|
|
}
|
|
|
|
- (UIImageView *)ownerImageView {
|
|
if (!_ownerImageView) {
|
|
_ownerImageView = [[UIImageView alloc] init];
|
|
_ownerImageView.userInteractionEnabled = YES;
|
|
_ownerImageView.image = [UIImage imageNamed:@"monents_common_landLordFlag"];
|
|
_ownerImageView.hidden = YES;
|
|
}
|
|
return _ownerImageView;
|
|
}
|
|
|
|
|
|
@end
|