220 lines
7.2 KiB
Objective-C
220 lines
7.2 KiB
Objective-C
//
|
|
// XPHomeRedommendCollectionViewCell.m
|
|
// xplan-ios
|
|
//
|
|
// Created by GreenLand on 2022/9/23.
|
|
//
|
|
|
|
#import "XPHomeRedommendCollectionViewCell.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
///Tool
|
|
#import "ThemeColor+Home.h"
|
|
#import "NetImageView.h"
|
|
#import "UIImage+Utils.h"
|
|
///Model
|
|
#import "HomeRecommendRoomModel.h"
|
|
|
|
@interface XPHomeRedommendCollectionViewCell ()
|
|
///背景
|
|
@property (nonatomic,strong) UIView * backView;
|
|
///头像
|
|
@property (nonatomic,strong) NetImageView *avatarImageView;
|
|
///容器
|
|
@property (nonatomic,strong) UIView * personContainerView;
|
|
///显示🔥
|
|
@property (nonatomic,strong) UIImageView *hotImageView;
|
|
///显示在线人数
|
|
@property (nonatomic,strong) UILabel *numberLabel;
|
|
///名字下的阴影
|
|
@property (nonatomic,strong) UIImageView *shadowImageView;
|
|
///显示名字
|
|
@property (nonatomic,strong) UILabel *nickLabel;
|
|
///标签
|
|
@property (nonatomic,strong) UIButton *tagButton;
|
|
@end
|
|
|
|
@implementation XPHomeRedommendCollectionViewCell
|
|
|
|
- (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.backView];
|
|
|
|
[self.backView addSubview:self.avatarImageView];
|
|
[self.backView addSubview:self.shadowImageView];
|
|
[self.backView addSubview:self.personContainerView];
|
|
[self.backView addSubview:self.nickLabel];
|
|
[self.backView addSubview:self.tagButton];
|
|
|
|
[self.personContainerView addSubview:self.hotImageView];
|
|
[self.personContainerView addSubview:self.numberLabel];
|
|
}
|
|
|
|
- (void)initSubViewConstraints {
|
|
[self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.edges.mas_equalTo(self);
|
|
}];
|
|
|
|
[self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.edges.mas_equalTo(self);
|
|
}];
|
|
|
|
[self.hotImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.size.mas_equalTo(CGSizeMake(13, 13));
|
|
make.right.mas_equalTo(self.numberLabel.mas_left).offset(-2);
|
|
make.centerY.mas_equalTo(self.personContainerView);
|
|
}];
|
|
|
|
[self.numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.right.mas_equalTo(self.personContainerView.mas_right).offset(-4);
|
|
make.centerY.mas_equalTo(self.personContainerView);
|
|
}];
|
|
|
|
[self.shadowImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.right.mas_equalTo(self.backView);
|
|
make.height.mas_equalTo(48);
|
|
make.bottom.mas_equalTo(self.backView);
|
|
}];
|
|
|
|
[self.tagButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.left.mas_equalTo(self.backView);
|
|
make.size.mas_equalTo(CGSizeMake(54, 20));
|
|
}];
|
|
[self.nickLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(self.backView).offset(6);
|
|
make.right.mas_equalTo(self.backView).offset(-6);
|
|
make.centerY.mas_equalTo(self.shadowImageView);
|
|
}];
|
|
|
|
[self.personContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(self.hotImageView.mas_left).offset(-4);
|
|
make.height.mas_equalTo(16);
|
|
make.top.mas_equalTo(self.backView).offset(4);
|
|
make.right.mas_equalTo(self.backView).offset(-4);
|
|
}];
|
|
|
|
[self.shadowImageView mas_updateConstraints:^(MASConstraintMaker *make) {
|
|
make.height.mas_equalTo(28);
|
|
}];
|
|
}
|
|
|
|
|
|
#pragma mark - Getters And Setters
|
|
- (void)setRecommendRoomInfo:(HomeRecommendRoomModel *)recommendRoomInfo {
|
|
_recommendRoomInfo = recommendRoomInfo;
|
|
if (_recommendRoomInfo) {
|
|
self.avatarImageView.imageUrl = _recommendRoomInfo.avatar;
|
|
self.numberLabel.text = [NSString stringWithFormat:@"%ld", _recommendRoomInfo.onlineNum];
|
|
self.nickLabel.text = _recommendRoomInfo.title;
|
|
self.personContainerView.hidden = NO;
|
|
self.tagButton.hidden = NO;
|
|
if (_recommendRoomInfo.crossPking) {
|
|
[self.tagButton setTitle:@"PK中" forState:UIControlStateNormal];
|
|
} else {
|
|
if (_recommendRoomInfo.iconContent.length > 0) {
|
|
[self.tagButton setTitle:_recommendRoomInfo.iconContent forState:UIControlStateNormal];
|
|
} else {
|
|
self.tagButton.hidden = YES;
|
|
}
|
|
}
|
|
|
|
} else {
|
|
self.avatarImageView.image = [UIImage imageNamed:@"home_recommend_room_placeholder"];
|
|
self.nickLabel.text = @"虚位以待";
|
|
self.personContainerView.hidden = YES;
|
|
self.tagButton.hidden = YES;
|
|
}
|
|
}
|
|
|
|
- (UIView *)backView {
|
|
if (!_backView) {
|
|
_backView = [[UIView alloc] init];
|
|
_backView.backgroundColor = [UIColor clearColor];
|
|
_backView.layer.masksToBounds = YES;
|
|
_backView.layer.cornerRadius = 8;
|
|
_backView.layer.shadowColor = UIColorRGBAlpha(0xE5E5F2, 0.34).CGColor;
|
|
_backView.layer.shadowOffset = CGSizeMake(3, 3);
|
|
}
|
|
return _backView;
|
|
}
|
|
|
|
- (NetImageView *)avatarImageView {
|
|
if (!_avatarImageView) {
|
|
NetImageConfig * config = [[NetImageConfig alloc]init];
|
|
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
|
|
_avatarImageView = [[NetImageView alloc] initWithConfig:config];
|
|
_avatarImageView.layer.masksToBounds = YES;
|
|
_avatarImageView.layer.cornerRadius = 8;
|
|
}
|
|
return _avatarImageView;
|
|
}
|
|
|
|
- (UIButton *)tagButton {
|
|
if (!_tagButton) {
|
|
_tagButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_tagButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
|
_tagButton.titleLabel.font = [UIFont systemFontOfSize:10];
|
|
[_tagButton setBackgroundImage:[UIImage imageNamed:@"home_recommend_tag_bg"] forState:UIControlStateNormal];
|
|
}
|
|
return _tagButton;
|
|
}
|
|
|
|
- (UIView *)personContainerView {
|
|
if (!_personContainerView) {
|
|
_personContainerView = [[UIView alloc] init];
|
|
_personContainerView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.29];
|
|
_personContainerView.layer.masksToBounds = YES;
|
|
_personContainerView.layer.cornerRadius = 8;
|
|
}
|
|
return _personContainerView;
|
|
}
|
|
|
|
- (UIImageView *)hotImageView {
|
|
if (!_hotImageView) {
|
|
_hotImageView = [[UIImageView alloc] init];
|
|
_hotImageView.userInteractionEnabled = YES;
|
|
_hotImageView.image = [UIImage imageNamed:@"room_like_collect_room_hot"];
|
|
}
|
|
return _hotImageView;
|
|
}
|
|
|
|
- (UILabel *)nickLabel {
|
|
if (!_nickLabel) {
|
|
_nickLabel = [[UILabel alloc] init];
|
|
_nickLabel.font = [UIFont boldSystemFontOfSize:12];
|
|
_nickLabel.textColor = [UIColor whiteColor];
|
|
_nickLabel.textAlignment = NSTextAlignmentCenter;
|
|
}
|
|
return _nickLabel;
|
|
}
|
|
|
|
- (UILabel *)numberLabel {
|
|
if (!_numberLabel) {
|
|
_numberLabel = [[UILabel alloc] init];
|
|
_numberLabel.font = [UIFont systemFontOfSize:9];
|
|
_numberLabel.textColor = [UIColor whiteColor];
|
|
}
|
|
return _numberLabel;
|
|
}
|
|
|
|
- (UIImageView *)shadowImageView {
|
|
if (!_shadowImageView) {
|
|
_shadowImageView = [[UIImageView alloc] init];
|
|
_shadowImageView.userInteractionEnabled = YES;
|
|
_shadowImageView.image = [UIImage imageNamed:@"home_recommend_nick_shadow_bg"];
|
|
}
|
|
return _shadowImageView;
|
|
}
|
|
|
|
@end
|