316 lines
13 KiB
Objective-C
316 lines
13 KiB
Objective-C
//
|
|
// XPMineAttentionTableViewCell.m
|
|
// xplan-ios
|
|
//
|
|
// Created by 冯硕 on 2021/12/21.
|
|
//
|
|
|
|
#import "XPMineAttentionTableViewCell.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
///Tool
|
|
#import "NetImageView.h"
|
|
#import "UIImage+Utils.h"
|
|
///Model
|
|
#import "FansInfoModel.h"
|
|
|
|
@interface XPMineAttentionTableViewCell ()
|
|
///头像
|
|
@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;
|
|
///贵族
|
|
@property (nonatomic,strong) NetImageView *nobleImageView;
|
|
///签名
|
|
@property (nonatomic,strong) UILabel *signLabel;
|
|
///找到他
|
|
@property (nonatomic,strong) UIButton *findButton;
|
|
|
|
@end
|
|
|
|
|
|
@implementation XPMineAttentionTableViewCell
|
|
- (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;
|
|
[self.contentView addSubview:self.avatarImageView];
|
|
[self.contentView addSubview:self.stackView];
|
|
[self.contentView addSubview:self.signLabel];
|
|
[self.contentView addSubview:self.findButton];
|
|
|
|
|
|
[self.stackView addArrangedSubview:self.nobleImageView];
|
|
[self.stackView addArrangedSubview:self.nickLabel];
|
|
[self.stackView addArrangedSubview:self.sexImageView];
|
|
[self.stackView addArrangedSubview:self.experImageView];
|
|
[self.stackView addArrangedSubview:self.charmImageView];
|
|
}
|
|
|
|
- (void)initSubViewConstraints {
|
|
[self.avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.size.mas_equalTo(CGSizeMake((50), (50)));
|
|
make.centerY.mas_equalTo(self.contentView);
|
|
make.left.mas_equalTo(self.contentView).offset((15));
|
|
}];
|
|
|
|
[self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(self.avatarImageView.mas_right).offset((10));
|
|
make.right.mas_lessThanOrEqualTo(self.findButton.mas_left).mas_offset(-0);
|
|
make.height.mas_equalTo(((20)));
|
|
make.top.equalTo(self.avatarImageView.mas_top).mas_offset((3));
|
|
}];
|
|
[self.sexImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.width.mas_equalTo(28);
|
|
make.height.mas_equalTo(14);
|
|
}];
|
|
// [self.nickLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
// make.width.mas_lessThanOrEqualTo((100));
|
|
// }];
|
|
[self.signLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(self.stackView);
|
|
make.top.equalTo(self.stackView.mas_bottom).mas_offset((7));
|
|
make.right.mas_equalTo(self.findButton.mas_left).mas_offset(-(10));
|
|
}];
|
|
|
|
[self.findButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.width.mas_equalTo((68));
|
|
make.height.mas_equalTo((30));
|
|
make.centerY.mas_equalTo(self.contentView);
|
|
make.right.mas_equalTo(self.contentView).offset(-(15));
|
|
}];
|
|
|
|
|
|
}
|
|
|
|
#pragma mark - Event Response
|
|
- (void)findButtonAction:(UIButton *)sender {
|
|
if (self.delegate && [self.delegate respondsToSelector:@selector(xPMineAttentionTableViewCell:findUser:)]) {
|
|
[self.delegate xPMineAttentionTableViewCell:self findUser:self.fansInfo.userInRoomUid];
|
|
}
|
|
}
|
|
|
|
#pragma mark - Getters And Setters
|
|
- (void)setFansInfo:(FansInfoModel *)fansInfo {
|
|
_fansInfo = fansInfo;
|
|
if (_fansInfo) {
|
|
self.avatarImageView.imageUrl = _fansInfo.avatar;
|
|
if(_fansInfo.nick.length > 5){
|
|
_fansInfo.nick = [NSString stringWithFormat:@"%@...",[_fansInfo.nick substringToIndex:5]];
|
|
}
|
|
self.nickLabel.text = _fansInfo.nick;
|
|
self.signLabel.text = _fansInfo.userDesc && _fansInfo.userDesc.length > 0? _fansInfo.userDesc : YMLocalizedString(@"XPMineAttentionTableViewCell0");
|
|
if (_fansInfo.useingType != ContactUseingType_In_Room && _fansInfo.useingType != ContactUseingType_Share) {
|
|
self.experImageView.hidden = NO;
|
|
self.charmImageView.hidden = NO;
|
|
if (_fansInfo.userVipInfoVO.vipIcon != nil) {
|
|
self.nobleImageView.hidden = NO;
|
|
}else{
|
|
self.nobleImageView.hidden = YES;
|
|
}
|
|
self.sexImageView.hidden = NO;
|
|
self.experImageView.imageUrl = _fansInfo.experUrl;
|
|
self.charmImageView.imageUrl = _fansInfo.charmUrl;
|
|
self.nobleImageView.imageUrl = _fansInfo.userVipInfoVO.vipIcon;
|
|
[self.sexImageView setTitle:[NSString getAgeWithBirth:_fansInfo.birth] forState:UIControlStateNormal];
|
|
self.sexImageView.backgroundColor = _fansInfo.gender == GenderType_Male ? UIColorFromRGB(0x6BB3FF) :UIColorFromRGB(0xFF80CC);
|
|
self.sexImageView.titleEdgeInsets = _fansInfo.gender != GenderType_Male ? UIEdgeInsetsMake(0, 2, 0, 0):UIEdgeInsetsMake(0, -1, 0, 0);
|
|
self.sexImageView.selected = _fansInfo.gender != GenderType_Male;
|
|
|
|
self.findButton.hidden = _fansInfo.userInRoomUid.length <= 0;
|
|
UIImage* image = self.experImageView.image;
|
|
if (image) {
|
|
CGFloat scale = image.size.width / image.size.height;
|
|
[self.experImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
make.size.mas_equalTo(CGSizeMake(20* scale, 20));
|
|
}];
|
|
} else {
|
|
NSURL *imgUrl = [NSURL URLWithString:_fansInfo.experUrl];
|
|
UIImage *myImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:imgUrl]];
|
|
CGFloat scale = myImage.size.width / myImage.size.height;
|
|
[self.experImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
make.size.mas_equalTo(CGSizeMake(20* scale, 20));
|
|
}];
|
|
}
|
|
|
|
UIImage* charmImage = self.charmImageView.image;
|
|
if (charmImage) {
|
|
CGFloat scale = charmImage.size.width / charmImage.size.height;
|
|
[self.charmImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
make.size.mas_equalTo(CGSizeMake(20* scale, 20));
|
|
}];
|
|
} else {
|
|
NSURL *imgUrl = [NSURL URLWithString:_fansInfo.charmUrl];
|
|
UIImage *myImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:imgUrl]];
|
|
CGFloat scale = myImage.size.width / myImage.size.height;
|
|
[self.charmImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
|
|
make.size.mas_equalTo(CGSizeMake(20* scale, 20));
|
|
}];
|
|
}
|
|
|
|
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 = [DJDKMIMOMColor inputTextColor];
|
|
}
|
|
} else {
|
|
self.experImageView.hidden = YES;
|
|
self.charmImageView.hidden = YES;
|
|
self.nobleImageView.hidden = YES;
|
|
self.sexImageView.hidden = YES;
|
|
self.findButton.hidden = YES;
|
|
self.nickLabel.textColor = [DJDKMIMOMColor mainTextColor];
|
|
}
|
|
}
|
|
}
|
|
|
|
- (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 = kFontMedium(15);
|
|
_nickLabel.textColor = [DJDKMIMOMColor inputTextColor];
|
|
}
|
|
return _nickLabel;
|
|
}
|
|
|
|
- (UIButton *)sexImageView {
|
|
if (!_sexImageView) {
|
|
_sexImageView = [[UIButton alloc] init];
|
|
[_sexImageView setImage:kImage(@"home_age_boy_icon") forState:UIControlStateNormal];
|
|
[_sexImageView setImage:kImage(@"home_age_girl_icon") forState:UIControlStateSelected];
|
|
_sexImageView.titleLabel.font = [UIFont systemFontOfSize:10 weight:UIFontWeightMedium];
|
|
[_sexImageView setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
|
_sexImageView.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
|
|
_sexImageView.layer.cornerRadius = 14/2;
|
|
_sexImageView.layer.masksToBounds = YES;
|
|
}
|
|
return _sexImageView;
|
|
}
|
|
|
|
- (NetImageView *)experImageView {
|
|
if (!_experImageView) {
|
|
NetImageConfig * config = [[NetImageConfig alloc]init];
|
|
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
|
|
_experImageView = [[NetImageView alloc] initWithConfig:config];
|
|
_experImageView.layer.maskedCorners = YES;
|
|
_experImageView.contentMode = UIViewContentModeScaleAspectFit;
|
|
}
|
|
return _experImageView;
|
|
}
|
|
|
|
- (NetImageView *)charmImageView {
|
|
if (!_charmImageView) {
|
|
NetImageConfig * config = [[NetImageConfig alloc]init];
|
|
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
|
|
_charmImageView = [[NetImageView alloc] initWithConfig:config];
|
|
_charmImageView.layer.maskedCorners = YES;
|
|
_charmImageView.contentMode = UIViewContentModeScaleAspectFit;
|
|
}
|
|
return _charmImageView;
|
|
}
|
|
|
|
- (NetImageView *)nobleImageView {
|
|
if (!_nobleImageView) {
|
|
_nobleImageView = [[NetImageView alloc] init];
|
|
}
|
|
return _nobleImageView;
|
|
}
|
|
|
|
- (UILabel *)signLabel{
|
|
if (!_signLabel) {
|
|
_signLabel = [[UILabel alloc] init];
|
|
_signLabel.textColor = [DJDKMIMOMColor disableButtonTextColor];
|
|
_signLabel.font = kFontMedium(12);
|
|
}
|
|
return _signLabel;
|
|
}
|
|
|
|
- (UIButton *)findButton {
|
|
if (!_findButton) {
|
|
_findButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_findButton setTitle:YMLocalizedString(@"XPMineAttentionTableViewCell1") forState:UIControlStateNormal];
|
|
[_findButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
|
UIImage *image = [UIImage gradientColorImageFromColors:@[[DJDKMIMOMColor confirmButtonGradientStartColor],[DJDKMIMOMColor confirmButtonGradientMiddleColor],[DJDKMIMOMColor confirmButtonGradientEndColor]] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake((68), (30))];
|
|
[_findButton setBackgroundImage:image forState:UIControlStateNormal];
|
|
_findButton.titleLabel.font = kFontMedium(14);
|
|
_findButton.layer.masksToBounds = YES;
|
|
_findButton.layer.cornerRadius = (15);
|
|
_findButton.hidden = YES;
|
|
[_findButton addTarget:self action:@selector(findButtonAction:) forControlEvents:UIControlEventTouchUpInside];
|
|
}
|
|
return _findButton;
|
|
}
|
|
|
|
|
|
|
|
@end
|