Files
yinmeng-ios/xplan-ios/Main/Home/View/Cell/XPSearchListTableViewCell.m
2022-01-14 15:48:47 +08:00

222 lines
6.8 KiB
Objective-C

//
// XPSearchListTableViewCell.m
// xplan-ios
//
// Created by 冯硕 on 2021/11/29.
//
#import "XPSearchListTableViewCell.h"
///Third
#import <Masonry/Masonry.h>
///Tool
#import "ThemeColor.h"
///Model
#import "HomeSearchResultModel.h"
///View
#import "NetImageView.h"
@interface XPSearchListTableViewCell ()
///头像
@property (nonatomic,strong) NetImageView *avatarImageView;
///名字的容器
@property (nonatomic,strong) UIStackView *nameStackView;
///昵称
@property (nonatomic,strong) UILabel *nickLabel;
///性别
@property (nonatomic,strong) UIImageView *sexImageView;
///显示id
@property (nonatomic,strong) UILabel *idLabel;
///分割线
@property (nonatomic,strong) UIView * lineView;
///容器
@property (nonatomic,strong) UIView * numberView;
///音符
@property (nonatomic,strong) UIImageView *noteImageView;
///数量
@property (nonatomic,strong) UILabel *numberLabel;
@end
@implementation XPSearchListTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
[self initSubViews];
[self initSubViewConstraints];
}
return self;
}
#pragma mark - Public Method
- (void)configData:(HomeSearchResultModel *)resultModel type:(SearchType)type {
if (resultModel) {
self.avatarImageView.imageUrl = resultModel.avatar;
self.nickLabel.text = type == SearchType_Room ? resultModel.title : resultModel.nick;
self.idLabel.text = [NSString stringWithFormat:@"%@号:%@",AppName, resultModel.erbanNo];
self.sexImageView.image = resultModel.gender == GenderType_Female ? [UIImage imageNamed:@"common_female"] : [UIImage imageNamed:@"common_male"];
if (type == SearchType_Users) {
self.numberLabel.text = @"直播中";
self.numberView.hidden = resultModel.roomUid.length <= 0;
} else {
if (resultModel.onlineNum > 100) {
self.numberLabel.text = [NSString stringWithFormat:@"%ld", resultModel.onlineNum];
} else {
self.numberLabel.text = [NSString stringWithFormat:@" %ld ", resultModel.onlineNum];
}
self.numberView.hidden = !resultModel.valid;
}
}
}
#pragma mark - Private Method
- (void)initSubViews {
self.selectionStyle = UITableViewCellSelectionStyleNone;
self.backgroundColor = [UIColor clearColor];
[self.contentView addSubview:self.avatarImageView];
[self.contentView addSubview:self.nameStackView];
[self.contentView addSubview:self.idLabel];
[self.contentView addSubview:self.numberView];
[self.contentView addSubview:self.lineView];
[self.numberView addSubview:self.numberLabel];
[self.numberView addSubview:self.noteImageView];
[self.nameStackView addArrangedSubview:self.nickLabel];
[self.nameStackView addArrangedSubview:self.sexImageView];
}
- (void)initSubViewConstraints {
[self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(45, 45));
make.left.mas_equalTo(self.contentView).offset(15);
make.centerY.mas_equalTo(self.contentView);
}];
[self.nameStackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.avatarImageView.mas_right).offset(13);
make.height.mas_equalTo(20);
make.bottom.mas_equalTo(self.avatarImageView.mas_centerY).offset(-1.5);
}];
[self.idLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.nameStackView);
make.top.mas_equalTo(self.avatarImageView.mas_centerY).offset(1.5);
}];
[self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.nameStackView);
make.right.mas_equalTo(self.contentView).offset(-15);
make.bottom.mas_equalTo(self.contentView);
make.height.mas_equalTo(1);
}];
[self.numberView mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(18);
make.right.mas_equalTo(self.contentView).offset(-15);
make.centerY.mas_equalTo(self.contentView);
make.left.mas_equalTo(self.noteImageView.mas_left).offset(-8);
}];
[self.numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(self.numberView);
make.right.mas_equalTo(self.numberView.mas_right).offset(-5);
}];
[self.noteImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(self.numberView);
make.size.mas_equalTo(CGSizeMake(10, 9));
make.right.mas_equalTo(self.numberLabel.mas_left).offset(-3);
}];
}
#pragma mark - Getters And Setters
- (NetImageView *)avatarImageView {
if (!_avatarImageView) {
NetImageConfig * config = [[NetImageConfig alloc] init];
config.imageType = ImageTypeUserIcon;
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
_avatarImageView = [[NetImageView alloc] initWithConfig:config];
_avatarImageView.layer.masksToBounds = YES;
_avatarImageView.layer.cornerRadius = 45/2;
_avatarImageView.contentMode = UIViewContentModeScaleAspectFill;
}
return _avatarImageView;
}
- (UIStackView *)nameStackView {
if (!_nameStackView) {
_nameStackView = [[UIStackView alloc] init];
_nameStackView.axis = UILayoutConstraintAxisHorizontal;
_nameStackView.distribution = UIStackViewDistributionFill;
_nameStackView.alignment = UIStackViewAlignmentCenter;
_nameStackView.spacing = 2;
}
return _nameStackView;
}
- (UILabel *)nickLabel {
if (!_nickLabel) {
_nickLabel = [[UILabel alloc] init];
_nickLabel.text = @"消息";
_nickLabel.font = [UIFont fontWithName:@"PingFang-SC-Medium" size:15];
_nickLabel.textColor = [ThemeColor secondTextColor];
}
return _nickLabel;
}
- (UIImageView *)sexImageView {
if (!_sexImageView) {
_sexImageView = [[UIImageView alloc] init];
_sexImageView.userInteractionEnabled = YES;
}
return _sexImageView;
}
- (UILabel *)idLabel {
if (!_idLabel) {
_idLabel = [[UILabel alloc] init];
_idLabel.font = [UIFont systemFontOfSize:13];
_idLabel.textColor = [ThemeColor textThirdColor];
}
return _idLabel;
}
- (UIView *)lineView {
if (!_lineView) {
_lineView = [[UIView alloc] init];
_lineView.backgroundColor = [ThemeColor dividerColor];
}
return _lineView;
}
- (UIView *)numberView {
if (!_numberView) {
_numberView = [[UIView alloc] init];
_numberView.backgroundColor = [UIColor clearColor];
_numberView.layer.masksToBounds = YES;
_numberView.layer.cornerRadius = 18/2;
_numberView.layer.borderColor = [ThemeColor appEmphasizeColor].CGColor;
_numberView.layer.borderWidth = 1;
}
return _numberView;
}
- (UIImageView *)noteImageView {
if (!_noteImageView) {
_noteImageView = [[UIImageView alloc] init];
_noteImageView.userInteractionEnabled = YES;
_noteImageView.image = [UIImage imageNamed:@"home_search_user_online"];
}
return _noteImageView;
}
- (UILabel *)numberLabel {
if (!_numberLabel) {
_numberLabel = [[UILabel alloc] init];
_numberLabel.text = @"直播中";
_numberLabel.font = [UIFont systemFontOfSize:10];
_numberLabel.textColor = [ThemeColor appEmphasizeColor];
}
return _numberLabel;
}
@end