Files
peko-ios/YuMi/Modules/YMMonents/View/SubViews/XPMoentsTopicView.m
2023-08-14 17:16:30 +08:00

121 lines
3.5 KiB
Objective-C

//
// XPMoentsTopicView.m
// xplan-ios
//
// Created by 冯硕 on 2022/5/12.
//
#import "XPMoentsTopicView.h"
///Third
#import <Masonry/Masonry.h>
///Tool
#import "UIImage+Utils.h"
#import "NSString+Utils.h"
///Model
#import "MonentsInfoModel.h"
@interface XPMoentsTopicView ()
///容器
@property (nonatomic,strong) UIStackView *stackView;
///背景
@property (nonatomic,strong) UIImageView *topicImageView;
///显示话题前面的#
@property (nonatomic,strong) UIImageView *iconImageView;
///显示话题
@property (nonatomic,strong) UILabel *topicLabel;
@end
@implementation XPMoentsTopicView
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self initSubViews];
[self initSubViewConstraints];
}
return self;
}
#pragma mark - Private Method
- (void)initSubViews {
[self addSubview:self.stackView];
[self.stackView addArrangedSubview:self.topicImageView];
[self.topicImageView addSubview:self.iconImageView];
[self.topicImageView addSubview:self.topicLabel];
}
- (void)initSubViewConstraints {
[self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.top.bottom.mas_equalTo(self);
}];
[self.topicImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.topicLabel.mas_right).offset(9);
}];
[self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.topicImageView);
make.size.mas_equalTo(CGSizeMake(10, 10));
make.centerY.mas_equalTo(self.topicImageView);
}];
[self.topicLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.iconImageView.mas_right).offset(4);
make.centerY.mas_equalTo(self.topicImageView);
}];
}
#pragma mark - Getters And Setters
- (void)setMonentsInfo:(MonentsInfoModel *)monentsInfo {
_monentsInfo = monentsInfo;
if (_monentsInfo) {
if (_monentsInfo.worldId > 0) {
self.topicLabel.text = _monentsInfo.worldName;
}
}
}
- (UIStackView *)stackView {
if (!_stackView) {
_stackView = [[UIStackView alloc] init];
_stackView.axis = UILayoutConstraintAxisHorizontal;
_stackView.distribution = UIStackViewDistributionFill;
_stackView.alignment = UIStackViewAlignmentFill;
_stackView.spacing = 8;
}
return _stackView;
}
- (UIImageView *)topicImageView {
if (!_topicImageView) {
_topicImageView = [[UIImageView alloc] init];
_topicImageView.userInteractionEnabled = YES;
// _topicImageView.image = [UIImage gradientColorImageFromColors:@[UIColorFromRGB(0xFFFCDD), UIColorFromRGB(0xDFF9FF), UIColorFromRGB(0xF4E5FF)] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(10, 10)];
_topicImageView.layer.masksToBounds = YES;
_topicImageView.layer.cornerRadius = 8;
}
return _topicImageView;
}
- (UIImageView *)iconImageView {
if (!_iconImageView) {
_iconImageView = [[UIImageView alloc] init];
_iconImageView.userInteractionEnabled = YES;
_iconImageView.image = [UIImage imageNamed:@"monents_info_topic_icon"];
}
return _iconImageView;
}
- (UILabel *)topicLabel {
if (!_topicLabel) {
_topicLabel = [[UILabel alloc] init];
_topicLabel.font = [UIFont systemFontOfSize:11 weight:UIFontWeightRegular];
_topicLabel.textColor = [DJDKMIMOMColor mainTextColor];
}
return _topicLabel;
}
@end