135 lines
3.7 KiB
Objective-C
135 lines
3.7 KiB
Objective-C
//
|
|
// XPMoentsTopicView.m
|
|
// xplan-ios
|
|
//
|
|
// Created by 冯硕 on 2022/5/12.
|
|
//
|
|
|
|
#import "XPMoentsTopicView.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
///Tool
|
|
#import "ThemeColor.h"
|
|
#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;
|
|
///显示时间
|
|
@property (nonatomic,strong) UILabel *timeLabel;
|
|
@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.stackView addArrangedSubview:self.timeLabel];
|
|
|
|
[self.topicImageView addSubview:self.iconImageView];
|
|
[self.topicImageView addSubview:self.topicLabel];
|
|
}
|
|
|
|
- (void)initSubViewConstraints {
|
|
[self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.edges.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).offset(9);
|
|
make.size.mas_equalTo(CGSizeMake(25 * 1.3, 10 * 1.3));
|
|
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.topicImageView.hidden = NO;
|
|
self.topicLabel.text = _monentsInfo.worldName;
|
|
} else {
|
|
self.topicImageView.hidden = YES;
|
|
}
|
|
self.timeLabel.text = [NSString stringWithTimeStamp:_monentsInfo.publishTime];
|
|
}
|
|
}
|
|
|
|
- (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:10 weight:UIFontWeightBold];
|
|
_topicLabel.textColor = [ThemeColor mainTextColor];
|
|
}
|
|
return _topicLabel;
|
|
}
|
|
|
|
- (UILabel *)timeLabel {
|
|
if (!_timeLabel) {
|
|
_timeLabel = [[UILabel alloc] init];
|
|
_timeLabel.font = [UIFont systemFontOfSize:10];
|
|
_timeLabel.textColor = [ThemeColor textThirdColor];
|
|
}
|
|
return _timeLabel;
|
|
}
|
|
|
|
@end
|