// // XPFindNewFriendTableViewCell.m // xplan-ios // // Created by XY on 2023/3/3. // #import "XPFindNewFriendTableViewCell.h" /// Third #import /// Tool #import "NetImageView.h" #import "ThemeColor.h" #import "XPButton.h" @interface XPFindNewFriendTableViewCell() /// 背景 @property (nonatomic, strong) UIView *bgView; /// 头像 @property (nonatomic, strong) NetImageView *avatarImageView; /// 在线状态 @property (nonatomic, strong) UIImageView *onlineImageView; @property (nonatomic, strong) UIStackView *nameStackView; /// 贵族图标 @property (nonatomic, strong) UIImageView *nobleImageView; /// 昵称 @property (nonatomic, strong) UILabel *nickLabel; @property (nonatomic, strong) UIStackView *constellationStackView; /// 性别年龄 @property (nonatomic, strong) UIButton *sexBtn; /// 星座 @property (nonatomic, strong) UILabel *constellationLabel; /// 签名 @property (nonatomic, strong) UILabel *signLabel; /// 直播中/和Ta聊 @property (nonatomic, strong) XPButton *livingBtn; @end @implementation XPFindNewFriendTableViewCell - (void)awakeFromNib { [super awakeFromNib]; // Initialization code } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { self.backgroundColor = UIColor.clearColor; self.contentView.backgroundColor = UIColor.clearColor; self.selectionStyle = UITableViewCellSelectionStyleNone; [self initSubViews]; [self initSubViewConstraints]; } return self; } #pragma mark - Private Method - (void)initSubViews { [self.contentView addSubview:self.bgView]; [self.bgView addSubview:self.avatarImageView]; [self.bgView addSubview:self.onlineImageView]; [self.bgView addSubview:self.nameStackView]; [self.bgView addSubview:self.constellationStackView]; [self.bgView addSubview:self.signLabel]; [self.bgView addSubview:self.livingBtn]; [self.nameStackView addArrangedSubview:self.nobleImageView]; [self.nameStackView addArrangedSubview:self.nickLabel]; [self.constellationStackView addArrangedSubview:self.sexBtn]; [self.constellationStackView addArrangedSubview:self.constellationLabel]; } - (void)initSubViewConstraints { [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(25); make.right.mas_equalTo(-15); make.top.mas_equalTo(6); make.bottom.mas_equalTo(-6); }]; [self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(-10); make.centerY.mas_equalTo(self.bgView); make.size.mas_equalTo(CGSizeMake(72, 72)); }]; [self.onlineImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(self.avatarImageView.mas_right).offset(-4); make.bottom.mas_equalTo(self.avatarImageView.mas_bottom).offset(-7); make.size.mas_equalTo(CGSizeMake(12, 12)); }]; [self.nameStackView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.avatarImageView.mas_right).offset(12); make.top.mas_equalTo(self.avatarImageView.mas_top).offset(4); make.height.mas_equalTo(21); }]; [self.nobleImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo(self.nobleImageView.mas_height); }]; [self.constellationStackView mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.mas_equalTo(self.avatarImageView); make.left.mas_equalTo(self.nameStackView); }]; [self.sexBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(15); }]; [self.signLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.nameStackView); make.bottom.mas_equalTo(self.avatarImageView.mas_bottom).offset(-4); }]; [self.livingBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(-15); make.centerY.mas_equalTo(self.bgView); }]; } #pragma mark - Getters And Setters - (void)setRoomInfo:(HomePlayRoomModel *)roomInfo { self.nobleImageView.hidden = YES; self.nickLabel.text = @"用户昵称"; [self.sexBtn setImage:[UIImage imageNamed:@"home_sex_female"] forState:UIControlStateNormal]; self.sexBtn.backgroundColor = [ThemeColor colorWithHexString:@"#FF9CCE"]; [self.sexBtn setTitle:@"22" forState:UIControlStateNormal]; self.constellationLabel.text = @"巨蟹座"; self.signLabel.text = @"我是个默认的个性签名"; [self.livingBtn setTitle:@"直播中" forState:UIControlStateNormal]; [self.livingBtn setImage:[UIImage imageNamed:@"home_living"] forState:UIControlStateNormal]; } - (UIView *)bgView { if (!_bgView) { _bgView = [[UIView alloc] init]; _bgView.backgroundColor = [ThemeColor appCellBackgroundColor]; _bgView.layer.cornerRadius = 10; } return _bgView; } - (NetImageView *)avatarImageView { if (!_avatarImageView) { NetImageConfig * config = [[NetImageConfig alloc] init]; config.placeHolder = [UIImageConstant defaultAvatarPlaceholder]; config.imageType = ImageTypeUserIcon; _avatarImageView = [[NetImageView alloc] initWithConfig:config]; _avatarImageView.userInteractionEnabled = YES; _avatarImageView.layer.masksToBounds = YES; _avatarImageView.layer.cornerRadius = 36; _avatarImageView.contentMode = UIViewContentModeScaleAspectFill; // UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTapAvatarGuest)]; // [_avatarImageView addGestureRecognizer:tap]; } return _avatarImageView; } - (UIImageView *)onlineImageView { if (!_onlineImageView) { _onlineImageView = [[UIImageView alloc] init]; _onlineImageView.backgroundColor = [ThemeColor colorWithHexString:@"#6CE19A"]; _onlineImageView.layer.cornerRadius = 6; _onlineImageView.layer.borderWidth = 2; _onlineImageView.layer.borderColor = UIColor.whiteColor.CGColor; _onlineImageView.clipsToBounds = YES; } return _onlineImageView; } - (UIStackView *)nameStackView { if (!_nameStackView) { _nameStackView = [[UIStackView alloc] init]; _nameStackView.axis = UILayoutConstraintAxisHorizontal; _nameStackView.distribution = UIStackViewDistributionFill; _nameStackView.alignment = UIStackViewAlignmentFill; _nameStackView.spacing = 3; } return _nameStackView; } - (UIImageView *)nobleImageView { if (!_nobleImageView) { _nobleImageView = [[UIImageView alloc] init]; _nobleImageView.contentMode = UIViewContentModeScaleAspectFit; } return _nobleImageView; } - (UILabel *)nickLabel { if (!_nickLabel) { _nickLabel = [[UILabel alloc] init]; _nickLabel.textColor = [ThemeColor mainTextColor]; _nickLabel.font = [UIFont systemFontOfSize:15 weight:UIFontWeightMedium]; } return _nickLabel; } - (UIStackView *)constellationStackView { if (!_constellationStackView) { _constellationStackView = [[UIStackView alloc] init]; _constellationStackView.axis = UILayoutConstraintAxisHorizontal; _constellationStackView.distribution = UIStackViewDistributionFill; _constellationStackView.alignment = UIStackViewAlignmentFill; _constellationStackView.spacing = 9; } return _constellationStackView; } - (UIButton *)sexBtn { if (!_sexBtn) { _sexBtn = [UIButton buttonWithType:UIButtonTypeCustom]; _sexBtn.titleLabel.font = [UIFont systemFontOfSize:10 weight:UIFontWeightRegular]; _sexBtn.layer.cornerRadius = 7.5; _sexBtn.clipsToBounds = YES; _sexBtn.userInteractionEnabled = NO; _sexBtn.contentEdgeInsets = UIEdgeInsetsMake(0, 4, 0, 4); // _sexBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 4, 0, 0); } return _sexBtn; } - (UILabel *)constellationLabel { if (!_constellationLabel) { _constellationLabel = [[UILabel alloc] init]; _constellationLabel.textColor = [ThemeColor textThirdColor]; _constellationLabel.font = [UIFont systemFontOfSize:10 weight:UIFontWeightRegular]; } return _constellationLabel; } - (UILabel *)signLabel { if (!_signLabel) { _signLabel = [[UILabel alloc] init]; _signLabel.textColor = [ThemeColor textThirdColor]; _signLabel.font = [UIFont systemFontOfSize:12 weight:UIFontWeightRegular]; } return _signLabel; } - (XPButton *)livingBtn { if (!_livingBtn) { _livingBtn = [XPButton buttonWithType:UIButtonTypeCustom]; _livingBtn.titleLabel.font = [UIFont systemFontOfSize:10 weight:UIFontWeightRegular]; [_livingBtn setTitleColor:[ThemeColor textThirdColor] forState:UIControlStateNormal]; _livingBtn.imagePosition = XPButtonImagePositionTop; _livingBtn.imageTitleSpace = 5; } return _livingBtn; } @end