Files
yinmeng-ios/xplan-ios/Main/Monents/View/Cell/XPMonentsTableViewCell.m
2022-08-26 21:38:47 +08:00

188 lines
5.6 KiB
Objective-C

//
// XPMonentsTableViewCell.m
// xplan-ios
//
// Created by 冯硕 on 2022/5/11.
//
#import "XPMonentsTableViewCell.h"
///Third
#import <Masonry/Masonry.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"
#import "XPMonentsContentView.h"
#import "XPMonentsLayoutConfig.h"
@interface XPMonentsTableViewCell ()<XPMonentsTooBarViewDelegate, XPMonentsTooBarViewDelegate>
///显示颜色的 有的时候stackView 不能显示颜色
@property (nonatomic,strong) UIView * backView;
///容器
@property (nonatomic,strong) UIStackView *stackView;
///用户信息
@property (nonatomic,strong) XPMonentsUserInfoView * userInfoView;
///显示内容的
@property (nonatomic,strong) XPMonentsContentView *textView;
///图片
@property (nonatomic,strong) XPMonentsPhotoView *photoView;
///显示底部的操作栏
@property (nonatomic,strong) XPMonentsTooBarView *toolBarView;
///话题
@property (nonatomic,strong) XPMoentsTopicView *topicView;
@end
@implementation XPMonentsTableViewCell
- (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.textView];
[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.userInfoView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.top.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);
}];
}
#pragma mark - XPMonentsTooBarViewDelegate
- (void)xPMonentsTooBarView:(XPMonentsTooBarView *)view didClickLike:(MonentsInfoModel *)monentsInfo {
if (self.delegate && [self.delegate respondsToSelector:@selector(xPMonentsTableViewCell:didClickLike:)]) {
[self.delegate xPMonentsTableViewCell:self didClickLike:monentsInfo];
}
}
#pragma mark - Getters And Setters
- (void)setMonentsInfo:(MonentsInfoModel *)monentsInfo {
_monentsInfo = monentsInfo;
if (_monentsInfo) {
self.userInfoView.monentsInfo = _monentsInfo;
self.textView.monentsInfo = _monentsInfo;
self.photoView.dynamicResList = _monentsInfo.dynamicResList;
self.topicView.monentsInfo = _monentsInfo;
self.toolBarView.monentsInfo = _monentsInfo;
if (_monentsInfo.type == MonentsContentType_Text) {
self.photoView.hidden = YES;
[self.photoView mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(0);
}];
} else {
self.photoView.hidden = NO;
CGFloat picHeight = _monentsInfo.picHeight <=0 ? [XPMonentsLayoutConfig monentsPicHeight:_monentsInfo] : _monentsInfo.picHeight;
[self.photoView mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(picHeight);
}];
}
CGFloat contentHeight = _monentsInfo.contentHeight <=0 ? [XPMonentsLayoutConfig monentsContentHeight:_monentsInfo] : _monentsInfo.contentHeight;
[self.textView mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(contentHeight);
}];
}
}
- (UIView *)backView {
if (!_backView) {
_backView = [[UIView alloc] init];
_backView.backgroundColor = [ThemeColor appCellBackgroundColor];
}
return _backView;
}
- (XPMonentsUserInfoView *)userInfoView {
if (!_userInfoView) {
_userInfoView = [[XPMonentsUserInfoView alloc] init];
}
return _userInfoView;
}
- (XPMonentsPhotoView *)photoView {
if (!_photoView) {
_photoView = [[XPMonentsPhotoView alloc] init];
}
return _photoView;
}
- (UIStackView *)stackView {
if (!_stackView) {
_stackView = [[UIStackView alloc] init];
_stackView.axis = UILayoutConstraintAxisVertical;
_stackView.distribution = UIStackViewDistributionFill;
_stackView.alignment = UIStackViewAlignmentFill;
_stackView.spacing = kMONENTS_CONTENT_SPACAE_HEIGHT;
}
return _stackView;
}
- (XPMonentsContentView *)textView {
if (!_textView) {
_textView = [[XPMonentsContentView alloc] init];
}
return _textView;
}
- (XPMoentsTopicView *)topicView {
if (!_topicView) {
_topicView = [[XPMoentsTopicView alloc] init];
}
return _topicView;
}
- (XPMonentsTooBarView *)toolBarView {
if (!_toolBarView) {
_toolBarView = [[XPMonentsTooBarView alloc] init];
_toolBarView.delegate = self;
}
return _toolBarView;
}
@end