// // XPMineFansTableViewCell.m // xplan-ios // // Created by 冯硕 on 2021/12/21. // #import "XPMineFansTableViewCell.h" ///Third #import #import ///Tool #import "NetImageView.h" #import "UIImage+Utils.h" ///Model #import "FansInfoModel.h" @interface XPMineFansTableViewCell () ///头像 @property (nonatomic,strong) NetImageView *avatarImageView; ///容器 @property (nonatomic,strong) UIStackView *stackView; ///昵称 @property (nonatomic,strong) UILabel *nickLabel; ///性别 //@property (nonatomic,strong) UIButton *sexImageView; ///等级 @property (nonatomic,strong) NetImageView *experImageView; ///魅力等级 @property (nonatomic,strong) NetImageView *charmImageView; ///VIP @property (nonatomic,strong) NetImageView *nobleImageView; ///签名 @property (nonatomic,strong) UILabel *signLabel; ///关注 @property (nonatomic,strong) UIButton *attentionButton; @property (nonatomic, strong) UIView *container; @end @implementation XPMineFansTableViewCell - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { [self initSubViews]; [self initSubViewConstraints]; } return self; } #pragma mark - Private Method - (void)initSubViews { self.backgroundColor = [UIColor clearColor]; self.selectionStyle = UITableViewCellSelectionStyleNone; UIView *bottomSpace = [[UIView alloc] init]; [self.contentView addSubview:bottomSpace]; [bottomSpace mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.trailing.bottom.mas_equalTo(self.contentView); make.height.mas_equalTo(12); }]; UIView *container = [[UIView alloc] init]; container.backgroundColor = [UIColor whiteColor]; container.layer.cornerRadius = 10; [self.contentView addSubview:container]; [container mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(self.contentView); make.bottom.mas_equalTo(bottomSpace.mas_top); make.leading.mas_equalTo(16); make.trailing.mas_equalTo(-16); }]; [container addSubview:self.avatarImageView]; [container addSubview:self.stackView]; [container addSubview:self.signLabel]; [container addSubview:self.attentionButton]; [self.stackView addArrangedSubview:self.nickLabel]; [self.stackView addArrangedSubview:self.experImageView]; [self.stackView addArrangedSubview:self.charmImageView]; [self.stackView addArrangedSubview:self.nobleImageView]; _container = container; } - (void)initSubViewConstraints { [self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.size.mas_equalTo(CGSizeMake((50), (50))); make.centerY.mas_equalTo(self.container); make.leading.mas_equalTo(self.container).offset((15)); }]; [self.stackView mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.mas_equalTo(self.avatarImageView.mas_trailing).offset((10)); make.trailing.mas_lessThanOrEqualTo(self.attentionButton.mas_leading).mas_offset(-0); make.height.mas_equalTo(20); make.top.equalTo(self.avatarImageView.mas_top).mas_offset((3)); }]; [self.signLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.mas_equalTo(self.stackView); make.top.equalTo(self.stackView.mas_bottom).mas_offset((7)); make.trailing.mas_equalTo(self.attentionButton.mas_leading).mas_offset(-(10)); }]; [self.attentionButton mas_makeConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo((68)); make.height.mas_equalTo((30)); make.centerY.mas_equalTo(self.container); make.trailing.mas_equalTo(self.container).offset(-(15)); }]; CGFloat width = 28 * 20 / 14; [self.charmImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(20); make.width.mas_equalTo(width); }]; [self.experImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(20); make.width.mas_equalTo(width); }]; } #pragma mark - Event Response - (void)attentionButtonAction:(UIButton *)sender { if (self.delegate && [self.delegate respondsToSelector:@selector(xPMineFansTableViewCell:didClickAttention:)]) { [self.delegate xPMineFansTableViewCell:self didClickAttention:self.fansInfo.uid]; } } #pragma mark - Getters And Setters - (void)setFansInfo:(FansInfoModel *)fansInfo { _fansInfo = fansInfo; if (_fansInfo) { self.avatarImageView.imageUrl = _fansInfo.avatar; self.nickLabel.text = _fansInfo.nick; self.signLabel.text = _fansInfo.userDesc && _fansInfo.userDesc.length > 0? _fansInfo.userDesc : YMLocalizedString(@"XPMineFansTableViewCell0"); if (_fansInfo.useingType != ContactUseingType_In_Room && _fansInfo.useingType != ContactUseingType_Share) { self.experImageView.hidden = NO; self.charmImageView.hidden = NO; if (_fansInfo.userVipInfoVO.nameplateUrl != nil) { self.nobleImageView.hidden = NO; }else{ self.nobleImageView.hidden = YES; } self.experImageView.imageUrl = _fansInfo.experUrl; self.charmImageView.imageUrl = _fansInfo.charmUrl; self.nobleImageView.imageUrl = _fansInfo.userVipInfoVO.nameplateUrl; BOOL isMyFriend = [[NIMSDK sharedSDK].userManager isMyFriend:_fansInfo.uid]; self.attentionButton.enabled = !isMyFriend; self.attentionButton.hidden = NO; UIImage *nobleImage = self.nobleImageView.image; if (nobleImage) { CGFloat scale = nobleImage.size.width / nobleImage.size.height; [self.nobleImageView mas_remakeConstraints:^(MASConstraintMaker *make) { make.size.mas_equalTo(CGSizeMake(20* scale, 20)); }]; } else { [self.nobleImageView mas_remakeConstraints:^(MASConstraintMaker *make) { make.size.mas_equalTo(CGSizeMake(0, 20)); }]; } if (fansInfo.userVipInfoVO && fansInfo.userVipInfoVO.friendNickColour) { self.nickLabel.textColor = [self colorWithHexString:fansInfo.userVipInfoVO.friendNickColour]; } else { self.nickLabel.textColor = UIColorFromRGB(0x333333); } } else { self.experImageView.hidden = YES; self.charmImageView.hidden = YES; self.nobleImageView.hidden = YES; self.attentionButton.hidden = YES; self.nickLabel.textColor = UIColorFromRGB(0x333333); } } } - (UIColor *)colorWithHexString: (NSString *) hexString { NSString *colorString = [[hexString stringByReplacingOccurrencesOfString: @"#" withString: @""] uppercaseString]; CGFloat alpha, red, blue, green; alpha = 1.0f; red = [self colorComponentFrom: colorString start: 0 length: 2]; green = [self colorComponentFrom: colorString start: 2 length: 2]; blue = [self colorComponentFrom: colorString start: 4 length: 2]; return [UIColor colorWithRed: red green: green blue: blue alpha: alpha]; } - (CGFloat) colorComponentFrom: (NSString *) string start: (NSUInteger) start length: (NSUInteger) length { NSString *substring = [string substringWithRange: NSMakeRange(start, length)]; NSString *fullHex = length == 2 ? substring : [NSString stringWithFormat: @"%@%@", substring, substring]; unsigned hexComponent; [[NSScanner scannerWithString: fullHex] scanHexInt: &hexComponent]; return hexComponent / 255.0; } - (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 = (50.0/2); } return _avatarImageView; } - (UIStackView *)stackView { if (!_stackView) { _stackView = [[UIStackView alloc] init]; _stackView.axis = UILayoutConstraintAxisHorizontal; _stackView.distribution = UIStackViewDistributionFill; _stackView.alignment = UIStackViewAlignmentCenter; _stackView.spacing = (4); } return _stackView; } - (UILabel *)nickLabel { if (!_nickLabel) { _nickLabel = [[UILabel alloc] init]; _nickLabel.font = kFontSemibold(14); _nickLabel.textColor = UIColorFromRGB(0x333333); } return _nickLabel; } - (NetImageView *)experImageView { if (!_experImageView) { NetImageConfig * config = [[NetImageConfig alloc]init]; _experImageView = [[NetImageView alloc] initWithConfig:config]; } return _experImageView; } - (NetImageView *)charmImageView { if (!_charmImageView) { NetImageConfig * config = [[NetImageConfig alloc]init]; _charmImageView = [[NetImageView alloc] initWithConfig:config]; } return _charmImageView; } - (NetImageView *)nobleImageView { if (!_nobleImageView) { _nobleImageView = [[NetImageView alloc] init]; } return _nobleImageView; } - (UILabel *)signLabel{ if (!_signLabel) { _signLabel = [[UILabel alloc] init]; _signLabel.textColor = UIColorFromRGB(0x7b7b7d); _signLabel.font = kFontRegular(13); } return _signLabel; } - (UIButton *)attentionButton { if (!_attentionButton) { _attentionButton = [UIButton buttonWithType:UIButtonTypeCustom]; _attentionButton.titleLabel.font = kFontMedium(14); _attentionButton.titleLabel.numberOfLines = 2; // 允许多行 _attentionButton.titleLabel.lineBreakMode = NSLineBreakByWordWrapping; _attentionButton.titleLabel.adjustsFontSizeToFitWidth = YES; // 关键 _attentionButton.titleLabel.minimumScaleFactor = 0.1; // 最小允许缩到 50% _attentionButton.titleLabel.lineBreakMode = NSLineBreakByClipping; _attentionButton.titleLabel.textAlignment = NSTextAlignmentCenter; _attentionButton.contentEdgeInsets = UIEdgeInsetsMake(0, 8, 0, 8); [_attentionButton setTitle:YMLocalizedString(@"XPMineFansTableViewCell1") forState:UIControlStateNormal]; [_attentionButton setTitleColor:UIColorFromRGB(0xFF8C03) forState:UIControlStateNormal]; [_attentionButton setBackgroundImage:[UIImage imageWithColor:[UIColor whiteColor]] forState:UIControlStateNormal]; [_attentionButton setTitle:YMLocalizedString(@"XPMineFansTableViewCell2") forState:UIControlStateDisabled]; [_attentionButton addTarget:self action:@selector(attentionButtonAction:) forControlEvents:UIControlEventTouchUpInside]; [_attentionButton setCornerRadius:15 corners:kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner | kCALayerMinXMaxYCorner | kCALayerMaxXMaxYCorner borderWidth:1 borderColor:UIColorFromRGB(0xFF8C03)]; [_attentionButton setCornerRadius:15]; } return _attentionButton; } @end