2022-05-11 16:32:10 +08:00
|
|
|
//
|
|
|
|
// XPMonentsTableViewCell.m
|
|
|
|
// xplan-ios
|
|
|
|
//
|
|
|
|
// Created by 冯硕 on 2022/5/11.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "XPMonentsTableViewCell.h"
|
2022-05-12 18:15:15 +08:00
|
|
|
///Third
|
|
|
|
#import <Masonry/Masonry.h>
|
|
|
|
#import <YYText/YYText.h>
|
|
|
|
///Tool
|
|
|
|
#import "ThemeColor.h"
|
|
|
|
#import "NetImageView.h"
|
|
|
|
#import "XPMonentsLayoutConfig.h"
|
|
|
|
///Model
|
|
|
|
#import "MonentsInfoModel.h"
|
|
|
|
///View
|
|
|
|
#import "XPMonentsUserInfoView.h"
|
|
|
|
#import "XPMonentsPhotoView.h"
|
|
|
|
#import "XPMonentsTooBarView.h"
|
|
|
|
#import "XPMoentsTopicView.h"
|
2022-05-11 16:32:10 +08:00
|
|
|
@interface XPMonentsTableViewCell ()
|
2022-05-12 18:15:15 +08:00
|
|
|
///显示颜色的 有的时候stackView 不能显示颜色
|
|
|
|
@property (nonatomic,strong) UIView * backView;
|
|
|
|
///容器
|
|
|
|
@property (nonatomic,strong) UIStackView *stackView;
|
|
|
|
///用户信息
|
|
|
|
@property (nonatomic,strong) XPMonentsUserInfoView * userInfoView;
|
|
|
|
///图片
|
|
|
|
@property (nonatomic,strong) XPMonentsPhotoView *photoView;
|
|
|
|
///显示底部的操作栏
|
|
|
|
@property (nonatomic,strong) XPMonentsTooBarView *toolBarView;
|
|
|
|
///显示内容
|
|
|
|
@property (nonatomic,strong) YYLabel *contentLabel;
|
|
|
|
///话题
|
|
|
|
@property (nonatomic,strong) XPMoentsTopicView *topicView;
|
2022-05-11 16:32:10 +08:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation XPMonentsTableViewCell
|
|
|
|
|
2022-05-12 18:15:15 +08:00
|
|
|
- (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.backView];
|
|
|
|
|
|
|
|
[self.backView addSubview:self.userInfoView];
|
|
|
|
[self.backView addSubview:self.stackView];
|
|
|
|
[self.backView addSubview:self.toolBarView];
|
|
|
|
|
|
|
|
[self.stackView addArrangedSubview:self.contentLabel];
|
|
|
|
[self.stackView addArrangedSubview:self.photoView];
|
|
|
|
[self.stackView addArrangedSubview:self.topicView];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)initSubViewConstraints {
|
|
|
|
[self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.edges.mas_equalTo(self.contentView);
|
|
|
|
}];
|
|
|
|
|
|
|
|
[self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.edges.mas_equalTo(self.contentView);
|
|
|
|
}];
|
|
|
|
|
|
|
|
[self.userInfoView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.left.mas_equalTo(self.backView);
|
|
|
|
make.right.mas_equalTo(self.backView);
|
|
|
|
make.height.mas_equalTo(kMONENTS_USER_INFO_HEIGHT);
|
|
|
|
}];
|
|
|
|
|
|
|
|
[self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.left.mas_equalTo(self.backView).offset(kMONENTS_CONTENT_LEFT_PADDING);
|
|
|
|
make.right.mas_equalTo(self.backView).offset(kMONENTS_CONTENT_RIGHT_PADDING);
|
|
|
|
make.top.mas_equalTo(self.userInfoView.mas_bottom).offset(kMONENTS_CONTENT_SPACAE_HEIGHT);
|
|
|
|
}];
|
|
|
|
|
|
|
|
[self.topicView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.height.mas_equalTo(kMONENTS_TEXT_TOPIC_HEIGHT);
|
|
|
|
}];
|
|
|
|
|
|
|
|
[self.toolBarView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.left.right.mas_equalTo(self.backView);
|
|
|
|
make.top.mas_equalTo(self.stackView.mas_bottom);
|
|
|
|
make.height.mas_equalTo(kMONENTS_TOOL_BAR_HEIGHT);
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSAttributedString *)createMonentsContentAttribute {
|
|
|
|
NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init];
|
|
|
|
if (self.monentsInfo.squareTop) {
|
|
|
|
[attribute appendAttributedString:[self createImageAttribute:[UIImage imageNamed:@""]]];
|
|
|
|
}
|
|
|
|
|
|
|
|
NSString * text = _monentsInfo.content;
|
|
|
|
if (text == nil || text.length <= 0) {
|
|
|
|
text = @"";
|
|
|
|
}
|
|
|
|
NSMutableAttributedString *contentAttribute = [[NSMutableAttributedString alloc] initWithString:text attributes:nil];
|
|
|
|
contentAttribute.yy_font = [UIFont systemFontOfSize:14];
|
|
|
|
contentAttribute.yy_color = [ThemeColor mainTextColor];
|
|
|
|
contentAttribute.yy_paragraphStyle = [self paragraphStyle];
|
|
|
|
[attribute appendAttributedString:contentAttribute];
|
|
|
|
return attribute;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// 生成本地一个图片的富文本
|
|
|
|
/// @param image 本地的图片
|
|
|
|
- (NSMutableAttributedString *)createImageAttribute:(UIImage *)image {
|
|
|
|
UIImageView *imaveView = [[UIImageView alloc]init];
|
|
|
|
imaveView.image = image;
|
|
|
|
CGFloat scale = (CGFloat)imaveView.image.size.width / (CGFloat)imaveView.image.size.height;
|
|
|
|
imaveView.bounds = CGRectMake(0, 0, 20 * scale, 20);
|
|
|
|
NSMutableAttributedString * attrString = [NSMutableAttributedString yy_attachmentStringWithContent:imaveView contentMode:UIViewContentModeScaleAspectFit attachmentSize:CGSizeMake(imaveView.frame.size.width, imaveView.frame.size.height) alignToFont:[UIFont systemFontOfSize:15.0] alignment:YYTextVerticalAlignmentCenter];
|
|
|
|
return attrString;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// 设置文本的样式 间隙 缩进 ...
|
|
|
|
- (NSMutableParagraphStyle *)paragraphStyle {
|
|
|
|
NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
|
|
|
|
paraStyle.lineSpacing = 4.0f;//行间距
|
|
|
|
// 强制排版(从左到右)
|
|
|
|
paraStyle.alignment = NSTextAlignmentLeft;
|
|
|
|
paraStyle.baseWritingDirection = NSWritingDirectionLeftToRight;
|
|
|
|
return paraStyle;
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - Getters And Setters
|
|
|
|
- (void)setMonentsInfo:(MonentsInfoModel *)monentsInfo {
|
|
|
|
_monentsInfo = monentsInfo;
|
|
|
|
if (_monentsInfo) {
|
|
|
|
self.userInfoView.monentsInfo = _monentsInfo;
|
|
|
|
self.contentLabel.attributedText = [self createMonentsContentAttribute];
|
|
|
|
self.photoView.dynamicResList = _monentsInfo.dynamicResList;
|
|
|
|
self.photoView.hidden = _monentsInfo.type == MonentsContentType_Text;
|
|
|
|
self.topicView.monentsInfo = _monentsInfo;
|
|
|
|
self.toolBarView.monentsInfo = _monentsInfo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UIView *)backView {
|
|
|
|
if (!_backView) {
|
|
|
|
_backView = [[UIView alloc] init];
|
|
|
|
_backView.backgroundColor = [ThemeColor appCellBackgroundColor];
|
|
|
|
}
|
|
|
|
return _backView;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (XPMonentsUserInfoView *)userInfoView {
|
|
|
|
if (!_userInfoView) {
|
|
|
|
_userInfoView = [[XPMonentsUserInfoView alloc] init];
|
|
|
|
}
|
|
|
|
return _userInfoView;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (YYLabel *)contentLabel {
|
|
|
|
if (!_contentLabel) {
|
|
|
|
_contentLabel = [[YYLabel alloc] init];
|
|
|
|
_contentLabel.preferredMaxLayoutWidth = kMONENTS_CONTENT_MAX_WIDTH;
|
|
|
|
}
|
|
|
|
return _contentLabel;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (XPMonentsPhotoView *)photoView {
|
|
|
|
if (!_photoView) {
|
|
|
|
_photoView = [[XPMonentsPhotoView alloc] init];
|
|
|
|
}
|
|
|
|
return _photoView;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UIStackView *)stackView {
|
|
|
|
if (!_stackView) {
|
|
|
|
_stackView = [[UIStackView alloc] init];
|
|
|
|
_stackView.axis = UILayoutConstraintAxisHorizontal;
|
|
|
|
_stackView.distribution = UIStackViewDistributionFill;
|
|
|
|
_stackView.alignment = UIStackViewAlignmentFill;
|
|
|
|
_stackView.spacing = kMONENTS_CONTENT_SPACAE_HEIGHT;
|
|
|
|
}
|
|
|
|
return _stackView;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (XPMoentsTopicView *)topicView {
|
|
|
|
if (!_topicView) {
|
|
|
|
_topicView = [[XPMoentsTopicView alloc] init];
|
|
|
|
}
|
|
|
|
return _topicView;
|
|
|
|
}
|
2022-05-11 16:32:10 +08:00
|
|
|
|
2022-05-12 18:15:15 +08:00
|
|
|
- (XPMonentsTooBarView *)toolBarView {
|
|
|
|
if (!_toolBarView) {
|
|
|
|
_toolBarView = [[XPMonentsTooBarView alloc] init];
|
|
|
|
}
|
|
|
|
return _toolBarView;
|
|
|
|
}
|
2022-05-11 16:32:10 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@end
|