// // YOUPAILZSessionUserInfoCell.m // MSYOUPAI // // Created by CY on 2022/3/8. // Copyright © 2022 MS. All rights reserved. // #import "YOUPAILZSessionUserInfoCell.h" #import "YOUPAILZUserFeatureView.h" @interface YOUPAILZSessionUserInfoCell () @property (nonatomic, weak) UIImageView *youpaipavatarImgV; @property (nonatomic, weak) UILabel *youpaipnicknameL; @property (nonatomic, weak) UILabel *youpaipcityL; @property (nonatomic, weak) UILabel *youpaipsignL; @property (nonatomic, weak) UIView *youpaipfeatureBgV; //特征背景 @property (nonatomic, strong) NSMutableArray *youpaipfeatureItems; @end @implementation YOUPAILZSessionUserInfoCell - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{ if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { self.selectionStyle = UITableViewCellSelectionStyleNone; [self youpaifinitUI]; } return self; } - (void)youpaifinitUI{ UIImageView *youpaipavatarImgV = [[UIImageView alloc] init]; youpaipavatarImgV.contentMode = UIViewContentModeScaleAspectFill; youpaipavatarImgV.layer.cornerRadius = 10.0f; youpaipavatarImgV.clipsToBounds = YES; [self.contentView addSubview:youpaipavatarImgV]; self.youpaipavatarImgV = youpaipavatarImgV; [youpaipavatarImgV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(12.0f); make.top.offset(9.0f); make.size.mas_offset(CGSizeMake(63.0f, 63.0f)); }]; UILabel *youpaipnicknameL = [[UILabel alloc] init]; youpaipnicknameL.textColor = LZ273145Color; youpaipnicknameL.font = LCFont(14.0f); [self.contentView addSubview:youpaipnicknameL]; self.youpaipnicknameL = youpaipnicknameL; [youpaipnicknameL mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(youpaipavatarImgV.mas_right).offset(10.0f); make.top.offset(9.0f); }]; UILabel *youpaipcityL = [[UILabel alloc] init]; youpaipcityL.textColor = LZA3AABEColor; youpaipcityL.font = LCFont(10.0f); [self.contentView addSubview:youpaipcityL]; self.youpaipcityL = youpaipcityL; [youpaipcityL mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(youpaipavatarImgV.mas_right).offset(10.0f); make.top.equalTo(youpaipnicknameL.mas_bottom).offset(8.0f); }]; UILabel *youpaipsignL = [[UILabel alloc] init]; youpaipsignL.textColor = LZA3AABEColor; youpaipsignL.font = LCFont(12.0f); youpaipsignL.numberOfLines = 2; [self.contentView addSubview:youpaipsignL]; self.youpaipsignL = youpaipsignL; [youpaipsignL mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(youpaipavatarImgV.mas_right).offset(8.0f); make.top.equalTo(youpaipcityL.mas_bottom).offset(8.0f); make.right.offset(-12.0f); }]; UIView *youpaipfeatureBgV = [[UIView alloc] init]; [self.contentView addSubview:youpaipfeatureBgV]; self.youpaipfeatureBgV = youpaipfeatureBgV; [youpaipfeatureBgV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(youpaipcityL.mas_right).offset(4.0f); make.height.offset(12.0f); make.centerY.equalTo(youpaipcityL); }]; UIImageView *arrowImgView = [[UIImageView alloc]init]; arrowImgView.contentMode = UIViewContentModeScaleAspectFill; arrowImgView.image = [UIImage imageNamed:@"vqu_images_H_cell_arrow_gray"]; [self.contentView addSubview:arrowImgView]; [arrowImgView makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(-12.0f); make.centerY.equalTo(youpaipcityL); make.size.mas_equalTo(CGSizeMake(10, 10)); }]; } - (void)youpaifreloadWithModel:(NSDictionary *)dict{ [self.youpaipavatarImgV sd_setImageWithURL:[[LCTools getImageUrlWithAddress:dict[@"avatar"]] urlWithImageScale:60]]; self.youpaipnicknameL.text = dict[@"nickname"]; self.youpaipcityL.text = dict[@"city"]; self.youpaipsignL.text = dict[@"sign"]; NSMutableArray *features = [NSMutableArray array]; if ([dict[@"age"] integerValue] != 0) { [features addObject:[NSString stringWithFormat:@"%@岁", @([dict[@"age"] integerValue])]]; }else{ [features addObject:@"未知"]; } if ([NSString stringWithFormat:@"%@",dict[@"height"]].length != 0) { [features addObject:dict[@"height"]]; }else{ [features addObject:@"未知"]; } if ([NSString stringWithFormat:@"%@",dict[@"occupation"]].length != 0) { [features addObject:dict[@"occupation"]]; }else{ [features addObject:@"未知"]; } [self youpaifeditBtnCountWithCount:features.count]; YOUPAILZUserFeatureView *frontFeatureV = nil; for (NSInteger i = 0; i < self.youpaipfeatureItems.count; i ++) { YOUPAILZUserFeatureView *v = self.youpaipfeatureItems[i]; [v youpaifreloadWithFeature:features[i]]; [v mas_remakeConstraints:^(MASConstraintMaker *make) { if (frontFeatureV == nil) { make.left.offset(0.0f); }else{ make.left.equalTo(frontFeatureV.mas_right).offset(4.0f); } make.top.bottom.offset(0.0f); if (i == self.youpaipfeatureItems.count - 1) { make.right.offset(0.0f); } }]; frontFeatureV = v; } } - (void)youpaifeditBtnCountWithCount:(NSInteger)count{ if (count >= self.youpaipfeatureItems.count) { [self youpaifaddBtnWithCount:count - self.youpaipfeatureItems.count]; }else{ [self youpaifdeleteBtnWithCount:self.youpaipfeatureItems.count - count]; } } - (void)youpaifdeleteBtnWithCount:(NSInteger)count{ if (count != 0) { for (NSInteger i = 0; i < count; i ++) { YOUPAILZUserFeatureView *v = self.youpaipfeatureItems.lastObject; [self.youpaipfeatureItems removeLastObject]; [v removeFromSuperview]; } } } - (void)youpaifaddBtnWithCount:(NSInteger)count{ for (NSInteger i = 0; i < count; i ++) { [self youpaifcreateBtn]; } } - (void)youpaifcreateBtn{ YOUPAILZUserFeatureView *v = [[YOUPAILZUserFeatureView alloc] init]; [self.youpaipfeatureBgV addSubview:v]; [self.youpaipfeatureItems addObject:v]; } - (NSMutableArray *)youpaipfeatureItems{ if (_youpaipfeatureItems == nil) { _youpaipfeatureItems = [NSMutableArray array]; } return _youpaipfeatureItems; } @end