// // KBChildFansCell.m // YouHuiProject // // Created by 小花 on 2018/5/19. // Copyright © 2018年 kuxuan. All rights reserved. // #import "KBChildFansCell.h" @interface KBChildFansCell() @property (nonatomic, strong) UIImageView *iconView; @property (nonatomic, strong) UIImageView *tagImage; @property (nonatomic, strong) UILabel *name; @property (nonatomic, strong) UILabel *phoneNum; @property (nonatomic, strong) UILabel *date; @end @implementation KBChildFansCell + (instancetype)cellWithTableView:(UITableView *)tableView { static NSString *cellID = nil; cellID = NSStringFromClass([self class]); KBChildFansCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID]; if (!cell) { cell = [[KBChildFansCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID]; } return cell; } - (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 initSubViews]; } return self; } - (void)initSubViews { [self.contentView addSubview:self.iconView]; [self.contentView addSubview:self.tagImage]; [self.contentView addSubview:self.name]; [self.contentView addSubview:self.phoneNum]; [self.contentView addSubview:self.date]; [self.contentView addSubview:self.sencondFansSumBtn]; [self.contentView addSubview:self.updateBtn]; [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(15); make.width.height.mas_equalTo(50); make.centerY.mas_equalTo(self.mas_centerY); }]; [self.name mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.iconView.mas_right).mas_offset(15); make.top.mas_equalTo(15); make.width.mas_lessThanOrEqualTo(150); }]; [self.tagImage mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.name.mas_right).mas_offset(10); make.centerY.mas_equalTo(self.name.mas_centerY); make.width.mas_equalTo(55); make.height.mas_equalTo(15); }]; [self.phoneNum mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.mas_equalTo(-15); make.left.mas_equalTo(self.name); }]; [self.date mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.phoneNum.mas_right).mas_offset(10); make.centerY.mas_equalTo(self.phoneNum.mas_centerY); }]; [self.sencondFansSumBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(FITSIZE(-17)); make.height.equalTo(self.mas_height); make.centerY.equalTo(self.mas_centerY); make.width.mas_equalTo(100); }]; [self.updateBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(-15); make.centerY.mas_equalTo(self.mas_centerY); make.width.mas_equalTo(Fitsize(52)); make.height.mas_equalTo(Fitsize(17)); }]; } #pragma mark -事件 -(void)sencondFansAction{ if (self.delegate && [self.delegate respondsToSelector:@selector(recommendFansByUserID:withUserName:)]) { [self.delegate recommendFansByUserID:self.model.user_id withUserName:self.model.name]; } } #pragma mark -懒加载 - (UIImageView *)iconView { if (!_iconView) { _iconView = [[UIImageView alloc] init]; _iconView.contentMode = UIViewContentModeScaleAspectFill; _iconView.layer.masksToBounds = YES; _iconView.backgroundColor = [UIColor yhGrayColor]; [_iconView setImage:[UIImage imageNamed:@"login"]]; _iconView.layer.cornerRadius = 25; } return _iconView; } - (UIImageView *)tagImage { if (!_tagImage) { _tagImage = [[UIImageView alloc] init]; _tagImage.contentMode = UIViewContentModeScaleAspectFit; _tagImage.image = [UIImage imageNamed:@"Svip_icon"]; } return _tagImage; } - (UILabel *)name { if (!_name) { _name = [[UILabel alloc] init]; _name.textColor = [UIColor YHColorWithHex:0x333333]; _name.font = [UIFont systemFontOfSize:14]; _name.text = @"未知用户"; } return _name; } - (UILabel *)phoneNum { if (!_phoneNum) { _phoneNum = [[UILabel alloc] init]; _phoneNum.textColor = [UIColor YHColorWithHex:0x878787]; _phoneNum.font = [UIFont systemFontOfSize:12]; _phoneNum.text = @"****"; } return _phoneNum; } - (UILabel *)date { if (!_date) { _date = [[UILabel alloc] init]; _date.textColor = [UIColor YHColorWithHex:0x878787]; _date.font = [UIFont systemFontOfSize:12]; _date.text = @"--"; } return _date; } -(UIButton *)sencondFansSumBtn{ if (!_sencondFansSumBtn) { _sencondFansSumBtn=[UIButton buttonWithType:UIButtonTypeCustom]; [_sencondFansSumBtn setTitleColor:[UIColor YHColorWithHex:0xFF4633] forState:UIControlStateNormal]; _sencondFansSumBtn.titleLabel.font=[UIFont systemFontOfSize:12]; [_sencondFansSumBtn addTarget:self action:@selector(sencondFansAction) forControlEvents:UIControlEventTouchUpInside]; } return _sencondFansSumBtn; } - (UIButton *)updateBtn { if (!_updateBtn) { _updateBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_updateBtn setImage:[UIImage imageNamed:@"update_btn"] forState:UIControlStateNormal]; [_updateBtn addTarget:self action:@selector(updateBtnAction) forControlEvents:UIControlEventTouchUpInside]; } return _updateBtn; } - (void)updateBtnAction { if (self.updateAction) { self.updateAction(_model); } } -(void)setModel:(KBChildFansModel *)model{ _model=model; // @property(nonatomic,copy)NSString *name; //名称 // @property(nonatomic,copy)NSString *phone; // s手机号 // @property(nonatomic,copy)NSString *fansDevel; // f粉丝等级 1 一级粉丝 2二级粉丝 // @property(nonatomic,copy)NSString *fansNum; //一级粉丝邀请的人数 // @property(nonatomic,copy)NSString *first_level_vermicelli_time; //r如果粉丝等级为1 时间取这个 // @property(nonatomic,copy)NSString *second_level_vermicelli_time; //r如果粉丝等级为2 时间取这个 // @property(nonatomic,copy)NSString *level; //1 会员 2超级会员 3 运营商 self.name.text=model.name; // if (model.name.length > 10) { // [self.name mas_updateConstraints:^(MASConstraintMaker *make) { // make.width.mas_equalTo(150); // }]; // } self.phoneNum.text=model.phone; switch ([model.level integerValue]) { case 1: { self.tagImage.image = [UIImage imageNamed:@"Vip_icon"]; self.sencondFansSumBtn.hidden=YES; } break; case 2: case 3: { self.tagImage.image = [UIImage imageNamed:@"Svip_icon"]; } break; default: break; } switch ([model.fansDevel integerValue]) { case 1: { self.date.text=model.first_level_vermicelli_time; if ([model.fansNum integerValue]!=0) { [self.sencondFansSumBtn setTitle:[NSString stringWithFormat:@"推荐%@人>",model.fansNum] forState:UIControlStateNormal]; self.sencondFansSumBtn.hidden=NO; }else{ self.sencondFansSumBtn.hidden=YES; } } break; case 2: { self.date.text=model.second_level_vermicelli_time; self.sencondFansSumBtn.hidden=YES; } break; default: break; } [self.iconView sd_setImageWithURL:[NSURL URLWithString:model.img] placeholderImage:[UIImage imageNamed:@"login"]]; self.updateBtn.hidden = [model.level integerValue]==1 && model.uplevel.boolValue ? NO : YES; } @end