123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380 |
- //
- // YOUPAILZHomeActiveCell.m
- // MSYOUPAI
- //
- // Created by CY on 2022/2/28.
- // Copyright © 2022 MS. All rights reserved.
- //
- #import "YOUPAILZHomeActiveCell.h"
- #import "YOUPAILZUserFeatureView.h"
- @interface YOUPAILZHomeActiveCell ()
- @property (nonatomic, weak) UIImageView *youpaipavatarImgV; // 头像
- @property (nonatomic, weak) UIImageView *youpaipnewUserImgV; // 新人
- @property (nonatomic, weak) UIView *youpaiponlineStateV; // 在线状态
- @property (nonatomic, weak) UILabel *youpaipnicknameL; // 昵称
- @property (nonatomic, weak) UIImageView *youpaipimmortalImgV; // 真人
- @property (nonatomic, weak) UIImageView *youpaipvipImgV; // vip
- @property (nonatomic, weak) UILabel *youpaipcityL; // 城市
- @property (nonatomic, weak) UILabel *youpaipsignL; // 个性签名
- @property (nonatomic, weak) UIButton *youpaipAudioBtn; // 声音展示
- @property (nonatomic, weak) UILabel *youpaipAudioL; // 声音时长
- @property (nonatomic, weak) UIButton *youpaipchatBtn; // 私信
- @property (nonatomic, weak) UIView *youpaipfeatureBgV; //特征背景
- @property (nonatomic, strong) NSMutableArray <YOUPAILZUserFeatureView *> *youpaipfeatureItems;
- @property (nonatomic, strong) YOUPAILCHomeListModel *model;
- @end
- @implementation YOUPAILZHomeActiveCell
- - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
- if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
- self.selectionStyle = UITableViewCellSelectionStyleNone;
- self.backgroundColor = [UIColor clearColor];
- [self youpaifinitUI];
- }
- return self;
- }
- - (void)youpaifinitUI{
-
- UIView *bgV = [[UIView alloc] init];
- bgV.layer.cornerRadius = 10.0f;
- bgV.clipsToBounds = YES;
- bgV.backgroundColor = [UIColor whiteColor];
- [self.contentView addSubview:bgV];
-
- 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.centerY.equalTo(self.contentView);
- make.size.mas_offset(CGSizeMake(70.0f, 70.0f));
- }];
-
- [bgV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(youpaipavatarImgV.mas_left).offset(14.0f);
- make.top.bottom.offset(0.0f);
- make.right.offset(-12.0f);
- }];
-
-
- UIImageView *youpaipnewUserImgV = [[UIImageView alloc] init];
- youpaipnewUserImgV.image = [UIImage imageNamed:@"vqu_images_home_new_user"];
- youpaipnewUserImgV.hidden = YES;
- [youpaipavatarImgV addSubview:youpaipnewUserImgV];
- self.youpaipnewUserImgV = youpaipnewUserImgV;
- [youpaipnewUserImgV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.top.offset(0.0f);
- make.size.mas_offset(CGSizeMake(26.0f, 13.0f));
- }];
-
- UIView *youpaiponlineStateV = [[UIView alloc] init];
- youpaiponlineStateV.layer.cornerRadius = 6.0f;
- youpaiponlineStateV.layer.borderColor = [UIColor whiteColor].CGColor;
- youpaiponlineStateV.layer.borderWidth = 2.0f;
- youpaiponlineStateV.clipsToBounds = YES;
- youpaiponlineStateV.hidden = YES;
- [self.contentView addSubview:youpaiponlineStateV];
- self.youpaiponlineStateV = youpaiponlineStateV;
- [youpaiponlineStateV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.offset(9.0f);
- make.top.equalTo(youpaipavatarImgV.mas_top).offset(-3.0f);
- make.size.mas_offset(CGSizeMake(12.0f, 12.0f));
- }];
-
- UILabel *youpaipnicknameL = [[UILabel alloc] init];
- youpaipnicknameL.textColor = LZ273145Color;
- youpaipnicknameL.font = LCFont(14.0f);
- [bgV addSubview:youpaipnicknameL];
- self.youpaipnicknameL = youpaipnicknameL;
- [youpaipnicknameL mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(youpaipavatarImgV.mas_right).offset(8.0f);
- make.top.offset(12.0f);
- }];
- UIImageView *youpaipimmortalImgV = [[UIImageView alloc] init];
- youpaipimmortalImgV.image = [UIImage imageNamed:@"vqu_images_home_immortal"];
- youpaipimmortalImgV.hidden = YES;
- [bgV addSubview:youpaipimmortalImgV];
- self.youpaipimmortalImgV = youpaipimmortalImgV;
- [youpaipimmortalImgV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.offset(0.0f);
- make.centerY.equalTo(youpaipnicknameL);
- make.size.mas_offset(CGSizeMake(31.0f, 12.0f));
- }];
-
- UIImageView *youpaipvipImgV = [[UIImageView alloc] init];
- youpaipvipImgV.hidden = YES;
- [bgV addSubview:youpaipvipImgV];
- self.youpaipvipImgV = youpaipvipImgV;
- [youpaipvipImgV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.offset(0.0f);
- make.centerY.equalTo(youpaipnicknameL);
- make.size.mas_offset(CGSizeMake(30.0f, 19.0f));
- }];
-
- UIImageView *addressImgV = [[UIImageView alloc] init];
- addressImgV.image = [UIImage imageNamed:@"vqu_images_home_city"];
- [bgV addSubview:addressImgV];
- [addressImgV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(youpaipavatarImgV.mas_right).offset(8.0f);
- make.top.equalTo(youpaipnicknameL.mas_bottom).offset(3.0f);
- make.size.mas_offset(CGSizeMake(12.0f, 12.0f));
- }];
-
- UILabel *youpaipcityL = [[UILabel alloc] init];
- youpaipcityL.textColor = LZA3AABEColor;
- youpaipcityL.font = LCFont(10.0f);
- [bgV addSubview:youpaipcityL];
- self.youpaipcityL = youpaipcityL;
- [youpaipcityL mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(addressImgV.mas_right).offset(0.0f);
- make.centerY.equalTo(addressImgV);
- }];
-
- UIButton *youpaipchatBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [youpaipchatBtn setImage:[UIImage imageNamed:@"vqu_images_home_accost"] forState:UIControlStateNormal];
- [youpaipchatBtn setTitle:@"心动" forState:UIControlStateNormal];
- [youpaipchatBtn setTitleColor:LZ273145Color forState:UIControlStateNormal];
- youpaipchatBtn.titleLabel.font = LCFont(8.0f);
- [youpaipchatBtn addTarget:self action:@selector(youpaipchatBtnClick) forControlEvents:UIControlEventTouchUpInside];
- CGFloat totalHeight = 42.0f;
- CGFloat imageSize = 38.0f;
- CGFloat titleHeight = 10.0f;
- youpaipchatBtn.imageEdgeInsets = UIEdgeInsetsMake(- (totalHeight - imageSize), -(imageSize/2.0f), 0.0, - imageSize);
- youpaipchatBtn.titleEdgeInsets = UIEdgeInsetsMake(0, - imageSize, - (totalHeight - titleHeight), 0);
- [bgV addSubview:youpaipchatBtn];
- self.youpaipchatBtn = youpaipchatBtn;
- [youpaipchatBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.offset(-5.0f);
- make.size.mas_offset(CGSizeMake(38.0f, 42.0f));
- make.centerY.equalTo(bgV);
- }];
-
- UILabel *youpaipsignL = [[UILabel alloc] init];
- youpaipsignL.textColor = LZA3AABEColor;
- youpaipsignL.font = LCFont(12.0f);
- [bgV addSubview:youpaipsignL];
- self.youpaipsignL = youpaipsignL;
- [youpaipsignL mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(youpaipavatarImgV.mas_right).offset(8.0f);
- make.top.equalTo(addressImgV.mas_bottom).offset(8.0f);
- make.right.equalTo(youpaipchatBtn.mas_left).offset(-8.0f);
- }];
- UIButton *youpaipAudioBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [youpaipAudioBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_home_audio_stop"] forState:UIControlStateNormal];
- [youpaipAudioBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_home_audio_stop"] forState:UIControlStateHighlighted];
- [youpaipAudioBtn addTarget:self action:@selector(youpaipAudioBtnClick:) forControlEvents:UIControlEventTouchUpInside];
- [bgV addSubview:youpaipAudioBtn];
- self.youpaipAudioBtn = youpaipAudioBtn;
- [youpaipAudioBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(youpaipavatarImgV.mas_right).offset(8.0f);
- make.top.equalTo(addressImgV.mas_bottom).offset(8.0f);
- make.size.mas_offset(CGSizeMake(62.5f, 18.0f));
- }];
-
- UILabel *youpaipAudioL = [[UILabel alloc] init];
- youpaipAudioL.font = LCFont(10.0f);
- youpaipAudioL.textColor = LZ7C69FEColor;
- [youpaipAudioBtn addSubview:youpaipAudioL];
- self.youpaipAudioL = youpaipAudioL;
- [youpaipAudioL mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.offset(-5.0f);
- make.centerY.equalTo(youpaipAudioBtn);
- }];
-
- UIView *youpaipfeatureBgV = [[UIView alloc] init];
- [bgV 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);
- }];
- }
- - (void)youpaifreloadWithModel:(YOUPAILCHomeListModel *)model{
- self.model = model;
- [self.youpaipavatarImgV sd_setImageWithURL:[[LCTools getImageUrlWithAddress:model.youpaipcover] urlWithImageScale:60]];
- if (model.youpaipis_new_user) {
- self.youpaiponlineStateV.hidden = YES;
- self.youpaipnewUserImgV.hidden = NO;
- }else{
- self.youpaiponlineStateV.hidden = NO;
- self.youpaipnewUserImgV.hidden = YES;
- }
-
- self.youpaiponlineStateV.backgroundColor = kColors(model.youpaipAddnewColor);
- self.youpaipnicknameL.text = model.youpaipnickname;
- self.youpaipcityL.text = model.youpaipcity;
- UIView *frontV = self.youpaipnicknameL;
- self.youpaipimmortalImgV.hidden = YES;
- if (model.youpaipis_anchor == 1) {
- self.youpaipimmortalImgV.hidden = NO;
- [self.youpaipimmortalImgV mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(frontV.mas_right).offset(2.0f);
- make.centerY.equalTo(self.youpaipnicknameL);
- make.size.mas_offset(CGSizeMake(31.0f, 12.0f));
- }];
- frontV = self.youpaipimmortalImgV;
- }
-
- self.youpaipvipImgV.hidden = YES;
- if (model.youpaipvip_icon.length != 0) {
- self.youpaipvipImgV.hidden = NO;
- [self.youpaipvipImgV sd_setImageWithURL:[LCTools getImageUrlWithAddress:model.youpaipvip_icon]];
- [self.youpaipvipImgV mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(frontV.mas_right).offset(2.0f);
- make.centerY.equalTo(self.youpaipnicknameL);
- make.size.mas_offset(CGSizeMake(30.0f, 19.0f));
- }];
- frontV = self.youpaipvipImgV;
- }
-
- self.youpaipsignL.text = model.youpaipsign;
- self.youpaipAudioBtn.hidden = YES;
- self.youpaipsignL.hidden = NO;
- if (model.youpaipvoice == 1) {
- self.youpaipAudioBtn.hidden = NO;
- self.youpaipsignL.hidden = YES;
- if (model.youpaipisPlay) {
- self.youpaipAudioL.text = [NSString stringWithFormat:@"%@\"",@(model.youpaipmp3_second - model.youpaipCurrentPlayTime)];
- [self.youpaipAudioBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_home_audio_play"] forState:UIControlStateNormal];
- [self.youpaipAudioBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_home_audio_play"] forState:UIControlStateHighlighted];
- }else{
- self.youpaipAudioL.text = [NSString stringWithFormat:@"%@\"",@(model.youpaipmp3_second)];
- [self.youpaipAudioBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_home_audio_stop"] forState:UIControlStateNormal];
- [self.youpaipAudioBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_home_audio_stop"] forState:UIControlStateHighlighted];
- }
- }
-
- if (model.youpaipis_beckon) { //心动 true 已心动过,false 未心动过
- [self.youpaipchatBtn setImage:[UIImage imageNamed:@"vqu_images_home_chat"] forState:UIControlStateNormal];
- [self.youpaipchatBtn setTitle:@"私信" forState:UIControlStateNormal];
- }else{
- [self.youpaipchatBtn setImage:[UIImage imageNamed:@"vqu_images_home_accost"] forState:UIControlStateNormal];
- [self.youpaipchatBtn setTitle:model.youpaipis_beckon_text forState:UIControlStateNormal];
- }
- // CGFloat totalHeight = 40.0f;
- // CGFloat imageSize = 38.0f;
- // CGFloat titleHeight = 10.0f;
- // self.youpaipchatBtn.imageEdgeInsets = UIEdgeInsetsMake(- (totalHeight - imageSize), -(imageSize/2.0f), 0.0, - imageSize);
- // self.youpaipchatBtn.titleEdgeInsets = UIEdgeInsetsMake(0, - imageSize, - (totalHeight - titleHeight), 0);
-
- NSMutableArray *features = [NSMutableArray array];
- if (model.youpaipage != 0) {
- [features addObject:[NSString stringWithFormat:@"%@岁", @(model.youpaipage)]];
- }
- if (model.youpaipheight.length != 0) {
- [features addObject:model.youpaipheight];
- }
- if (model.youpaipoccupation.length != 0) {
- [features addObject:model.youpaipoccupation];
- }
- [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)youpaifreloadCurrentPlayTime{
- self.youpaipAudioL.text = [NSString stringWithFormat:@"%@\"",@(self.model.youpaipmp3_second - self.model.youpaipCurrentPlayTime)];
- [self.youpaipAudioBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_home_audio_play"] forState:UIControlStateNormal];
- [self.youpaipAudioBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_home_audio_play"] forState:UIControlStateHighlighted];
- }
- - (void)youpaifstopPlay{
- self.youpaipAudioL.text = [NSString stringWithFormat:@"%@\"",@(self.model.youpaipmp3_second)];
- [self.youpaipAudioBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_home_audio_stop"] forState:UIControlStateNormal];
- [self.youpaipAudioBtn setBackgroundImage:[UIImage imageNamed:@"vqu_images_home_audio_stop"] forState:UIControlStateHighlighted];
- }
- /// 声音展示点击
- - (void)youpaipAudioBtnClick:(UIButton *)sender{
- sender.selected = !sender.selected;
- self.model.youpaipisPlay = sender.selected;
- if (sender.selected) {
- [sender setBackgroundImage:[UIImage imageNamed:@"vqu_images_home_audio_play"] forState:UIControlStateNormal];
- [sender setBackgroundImage:[UIImage imageNamed:@"vqu_images_home_audio_play"] forState:UIControlStateHighlighted];
- }else{
- [sender setBackgroundImage:[UIImage imageNamed:@"vqu_images_home_audio_stop"] forState:UIControlStateNormal];
- [sender setBackgroundImage:[UIImage imageNamed:@"vqu_images_home_audio_stop"] forState:UIControlStateHighlighted];
- }
-
- if (self.youpaipAudioClickBlock != nil) {
- self.youpaipAudioClickBlock(self.model,sender.selected);
- }
- }
- /// 搭讪、心动、私信点击
- - (void)youpaipchatBtnClick{
- // [self.youpaipchatBtn setImage:[UIImage imageNamed:@"vqu_images_home_chat"] forState:UIControlStateNormal];
- // [self.youpaipchatBtn setTitle:@"私信" forState:UIControlStateNormal];
- if (self.youpaipChatClickBlock != nil) {
- self.youpaipChatClickBlock(self.model);
- }
- }
- - (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<YOUPAILZUserFeatureView *> *)youpaipfeatureItems{
- if (_youpaipfeatureItems == nil) {
- _youpaipfeatureItems = [NSMutableArray array];
- }
- return _youpaipfeatureItems;
- }
- @end
|