口袋优选

KBGoodsRecommendTableViewCell.m 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. //
  2. // KBGoodsRecommendTableViewCell.m
  3. // YouHuiProject
  4. //
  5. // Created by jcymac on 2018/9/4.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "XLPlainFlowLayout.h"
  9. #import "KBGoodsRecommendTableViewCell.h"
  10. #import "KBGoodCollectionCell.h"
  11. #import "KBTodayModelView2.h"
  12. #import "UIView+SDAutoLayout.h"
  13. @interface KBGoodsRecommendTableViewCell()
  14. @property(nonatomic,strong)UIView *backView;
  15. @property(nonatomic,strong)UIImageView *topImgView;
  16. @property(nonatomic,strong)KBTodayModelView2 *scrollModelView;
  17. @end
  18. @implementation KBGoodsRecommendTableViewCell
  19. - (void)awakeFromNib {
  20. [super awakeFromNib];
  21. }
  22. + (instancetype)cellWithTableView:(UITableView *)tableView {
  23. static NSString *cellID = nil;
  24. cellID = NSStringFromClass([self class]);
  25. KBGoodsRecommendTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
  26. if (!cell) {
  27. cell = [[KBGoodsRecommendTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
  28. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  29. cell.backgroundColor=[UIColor yhGrayColor];
  30. }
  31. return cell;
  32. }
  33. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  34. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  35. if (self) {
  36. [self initSubViews];
  37. }
  38. return self;
  39. }
  40. -(void)initSubViews{
  41. [self.contentView addSubview:self.backView];
  42. [self.backView addSubview:self.topImgView];
  43. [self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
  44. make.left.mas_equalTo(Fitsize(10));
  45. make.right.mas_equalTo(-Fitsize(10));
  46. make.top.mas_equalTo(5);
  47. make.height.mas_equalTo(Fitsize(355));
  48. }];
  49. [self.topImgView mas_makeConstraints:^(MASConstraintMaker *make) {
  50. make.centerX.equalTo(self.backView.mas_centerX);
  51. make.top.mas_equalTo(Fitsize(5));
  52. make.width.mas_equalTo(Fitsize(345));
  53. make.height.mas_equalTo(Fitsize(345)*330/710.0f);
  54. }];
  55. 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];
  56. [self.scrollModelView setGoodData:nil];
  57. // KBChildGoodModel *model=[[KBChildGoodModel alloc]init];
  58. // model.title=@"hahahaha";
  59. // NSArray *topList =@[model,model,model,model];
  60. // [self.scrollModelView setGoodData:topList];
  61. [self.backView addSubview:self.scrollModelView];
  62. // [self setupAutoHeightWithBottomView:self.backView bottomMargin:10];
  63. }
  64. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  65. [super setSelected:selected animated:animated];
  66. }
  67. -(UIView *)backView{
  68. if (!_backView) {
  69. _backView=[[UIView alloc]init];
  70. _backView.backgroundColor=[UIColor whiteColor];
  71. _backView.layer.cornerRadius=5;
  72. }
  73. return _backView;
  74. }
  75. -(UIImageView *)topImgView{
  76. if (!_topImgView) {
  77. _topImgView=[[UIImageView alloc]init];
  78. _topImgView.layer.cornerRadius=7;
  79. _topImgView.layer.masksToBounds=YES;
  80. _topImgView.backgroundColor=[UIColor yhGrayColor];
  81. _topImgView.userInteractionEnabled=YES;
  82. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id _Nonnull sender) {
  83. if (self.delegate &&[self.delegate respondsToSelector:@selector(jumpByCommunityModel:)]) {
  84. [self.delegate jumpByCommunityModel:self.model];
  85. }
  86. }];
  87. [_topImgView addGestureRecognizer:tap];
  88. }
  89. return _topImgView;
  90. }
  91. - (void)setModel:(KBCommunityModel *)model {
  92. _model=model;
  93. NSMutableArray *muArray=[NSMutableArray array];
  94. self.scrollModelView.name=@"";
  95. self.scrollModelView.Id=@"0";
  96. for (KBCommunityDetailModel *deModel in model.detail) {
  97. KBChildGoodModel *changeModel=[KBChildGoodModel byCommunityDetailModel:deModel];
  98. [muArray addObject:changeModel];
  99. }
  100. [self.scrollModelView setGoodData:muArray];
  101. if ([model.banner isEqualToString:@""]) {
  102. [self.topImgView mas_updateConstraints:^(MASConstraintMaker *make) {
  103. make.height.mas_equalTo(0);
  104. }];
  105. self.scrollModelView.y=10;
  106. [self.backView mas_updateConstraints:^(MASConstraintMaker *make) {
  107. make.height.mas_equalTo(self.scrollModelView.height+20);
  108. }];
  109. }else{
  110. self.scrollModelView.y=Fitsize(345)*330/710.0f+Fitsize(10)+Fitsize(5);
  111. [self.topImgView mas_updateConstraints:^(MASConstraintMaker *make) {
  112. make.height.mas_equalTo(Fitsize(345)*330/710.0f);
  113. }];
  114. [self.backView mas_updateConstraints:^(MASConstraintMaker *make) {
  115. make.height.mas_equalTo(Fitsize(345));
  116. }];
  117. [self.topImgView sd_setImageWithURL:[NSURL URLWithString:model.banner]];
  118. }
  119. [self setupAutoHeightWithBottomView:self.scrollModelView bottomMargin:15];
  120. }
  121. @end