Files
yinmeng-ios/xplan-ios/Main/Monents/View/Cell/XPMonentsTopicCollectionViewCell.m
2023-01-04 17:21:42 +08:00

102 lines
2.7 KiB
Objective-C

//
// XPMonentsTopicCollectionViewCell.m
// xplan-ios
//
// Created by 冯硕 on 2022/5/18.
//
#import "XPMonentsTopicCollectionViewCell.h"
///Third
#import <Masonry/Masonry.h>
///Tool
#import "ThemeColor.h"
#import "UIImage+Utils.h"
#import "NetImageView.h"
///Model
#import "MonentsTopicModel.h"
@interface XPMonentsTopicCollectionViewCell ()
///背景
@property (nonatomic,strong) NetImageView *topicImageView;
///显示话题前面的#
@property (nonatomic,strong) UIImageView *iconImageView;
///显示话题
@property (nonatomic,strong) UILabel *topicLabel;
@end
@implementation XPMonentsTopicCollectionViewCell
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self initSubViews];
[self initSubViewConstraints];
}
return self;
}
#pragma mark - Private Method
- (void)initSubViews {
[self.contentView addSubview:self.topicImageView];
[self.topicImageView addSubview:self.iconImageView];
[self.topicImageView addSubview:self.topicLabel];
}
- (void)initSubViewConstraints {
[self.topicImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.contentView);
}];
[self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.bottom.mas_equalTo(self.topicImageView);
make.height.mas_equalTo(30);
}];
[self.topicLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.mas_equalTo(self.topicImageView).inset(2);
make.bottom.mas_equalTo(self.topicImageView.mas_bottom).offset(-6);
}];
}
#pragma mark - Getters And Setters
- (void)setTopicInfo:(MonentsTopicModel *)topicInfo {
_topicInfo = topicInfo;
if (_topicInfo) {
self.topicLabel.text = [NSString stringWithFormat:@"#%@", _topicInfo.name];
self.topicImageView.imageUrl = _topicInfo.icon;
}
}
- (NetImageView *)topicImageView {
if (!_topicImageView) {
NetImageConfig * config = [[NetImageConfig alloc]init];
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
_topicImageView = [[NetImageView alloc] initWithConfig:config];
_topicImageView.layer.masksToBounds = YES;
_topicImageView.layer.cornerRadius = 12;
_topicImageView.contentMode = UIViewContentModeScaleAspectFill;
}
return _topicImageView;
}
- (UIImageView *)iconImageView {
if (!_iconImageView) {
_iconImageView = [[UIImageView alloc] init];
_iconImageView.userInteractionEnabled = YES;
_iconImageView.image = [UIImage imageNamed:@"home_room_list_shadow_bg"];
}
return _iconImageView;
}
- (UILabel *)topicLabel {
if (!_topicLabel) {
_topicLabel = [[UILabel alloc] init];
_topicLabel.font = [UIFont systemFontOfSize:12 weight:UIFontWeightBold];
_topicLabel.textColor = [UIColor whiteColor];
_topicLabel.textAlignment = NSTextAlignmentCenter;
}
return _topicLabel;
}
@end