// // KBGoodsRecommendTableViewCell.m // YouHuiProject // // Created by jcymac on 2018/9/4. // Copyright © 2018年 kuxuan. All rights reserved. // #import "XLPlainFlowLayout.h" #import "KBGoodsRecommendTableViewCell.h" #import "KBGoodCollectionCell.h" #import "KBTodayModelView2.h" #import "UIView+SDAutoLayout.h" @interface KBGoodsRecommendTableViewCell() @property(nonatomic,strong)UIView *backView; @property(nonatomic,strong)UIImageView *topImgView; @property(nonatomic,strong)KBTodayModelView2 *scrollModelView; @end @implementation KBGoodsRecommendTableViewCell - (void)awakeFromNib { [super awakeFromNib]; } + (instancetype)cellWithTableView:(UITableView *)tableView { static NSString *cellID = nil; cellID = NSStringFromClass([self class]); KBGoodsRecommendTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID]; if (!cell) { cell = [[KBGoodsRecommendTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID]; cell.selectionStyle = UITableViewCellSelectionStyleNone; cell.backgroundColor=[UIColor yhGrayColor]; } return cell; } - (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.backView]; [self.backView addSubview:self.topImgView]; [self.backView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(Fitsize(10)); make.right.mas_equalTo(-Fitsize(10)); make.top.mas_equalTo(5); make.height.mas_equalTo(Fitsize(355)); }]; [self.topImgView mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self.backView.mas_centerX); make.top.mas_equalTo(Fitsize(5)); make.width.mas_equalTo(Fitsize(345)); make.height.mas_equalTo(Fitsize(345)*330/710.0f); }]; self.scrollModelView=[[KBTodayModelView2 alloc]initWithFrame:CGRectMake(0, Fitsize(345)*330/710.0f+Fitsize(10)+Fitsize(5), SCREEN_WIDTH-Fitsize(20), Fitsize(345)-(Fitsize(345)*330/710.0f+Fitsize(10)+Fitsize(10))-Fitsize(5)) titleNumOfLine:0]; [self.scrollModelView setGoodData:nil]; // KBChildGoodModel *model=[[KBChildGoodModel alloc]init]; // model.title=@"hahahaha"; // NSArray *topList =@[model,model,model,model]; // [self.scrollModelView setGoodData:topList]; [self.backView addSubview:self.scrollModelView]; // [self setupAutoHeightWithBottomView:self.backView bottomMargin:10]; } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; } -(UIView *)backView{ if (!_backView) { _backView=[[UIView alloc]init]; _backView.backgroundColor=[UIColor whiteColor]; _backView.layer.cornerRadius=5; } return _backView; } -(UIImageView *)topImgView{ if (!_topImgView) { _topImgView=[[UIImageView alloc]init]; _topImgView.layer.cornerRadius=7; _topImgView.layer.masksToBounds=YES; _topImgView.backgroundColor=[UIColor yhGrayColor]; _topImgView.userInteractionEnabled=YES; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id _Nonnull sender) { if (self.delegate &&[self.delegate respondsToSelector:@selector(jumpByCommunityModel:)]) { [self.delegate jumpByCommunityModel:self.model]; } }]; [_topImgView addGestureRecognizer:tap]; } return _topImgView; } - (void)setModel:(KBCommunityModel *)model { _model=model; NSMutableArray *muArray=[NSMutableArray array]; self.scrollModelView.name=@""; self.scrollModelView.Id=@"0"; for (KBCommunityDetailModel *deModel in model.detail) { KBChildGoodModel *changeModel=[KBChildGoodModel byCommunityDetailModel:deModel]; [muArray addObject:changeModel]; } [self.scrollModelView setGoodData:muArray]; if ([model.banner isEqualToString:@""]) { [self.topImgView mas_updateConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(0); }]; self.scrollModelView.y=10; [self.backView mas_updateConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(self.scrollModelView.height+20); }]; }else{ self.scrollModelView.y=Fitsize(345)*330/710.0f+Fitsize(10)+Fitsize(5); [self.topImgView mas_updateConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(Fitsize(345)*330/710.0f); }]; [self.backView mas_updateConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(Fitsize(345)); }]; [self.topImgView sd_setImageWithURL:[NSURL URLWithString:model.banner]]; } [self setupAutoHeightWithBottomView:self.scrollModelView bottomMargin:15]; } @end