// // DRContainerImageCell.m // YouHuiProject // // Created by 小花 on 2018/12/28. // Copyright © 2018年 kuxuan. All rights reserved. // #import "DRContainerImageCell.h" @interface DRContainerImageCell () @property (nonatomic, strong) UIImageView *imgView; @property (nonatomic, strong) UIButton *selectedBtn; @end @implementation DRContainerImageCell - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self initSubViews]; } return self; } - (void)initSubViews { [self.contentView addSubview:self.imgView]; [self.contentView addSubview:self.selectedBtn]; [self.contentView addSubview:self.qrImgLabel]; [self.imgView mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.mas_equalTo(UIEdgeInsetsMake(0, 0, 0, 0)); }]; [self.selectedBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.top.right.mas_equalTo(0); make.width.height.mas_equalTo(40); }]; [self.qrImgLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.bottom.mas_equalTo(0); make.height.mas_equalTo(28); }]; } - (void)selectAction { if (self.selectBlock) { self.selectBlock(); } } - (void)setModel:(DRShareImageCellModel *)model { if (model.imgUrl) { [self.imgView sd_setFadeImageWithURL:[NSURL URLWithString:model.imgUrl] placeholderImage:nil options:0 progress:nil completed:nil]; }else { if (model.shareImg) { self.imgView.image = model.shareImg; }else { self.imgView.image = nil; } } self.selectedBtn.selected = model.isSelected; } - (UIImageView *)imgView { if (!_imgView) { _imgView = [[UIImageView alloc] init]; _imgView.contentMode = UIViewContentModeScaleAspectFit; _imgView.backgroundColor = [UIColor whiteColor]; } return _imgView; } - (UIButton *)selectedBtn { if (!_selectedBtn) { _selectedBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_selectedBtn setImage:[UIImage imageNamed:@"cell_sel_n"] forState:UIControlStateNormal]; [_selectedBtn setImage:[UIImage imageNamed:@"cell_sel_s"] forState:UIControlStateSelected]; [_selectedBtn addTarget:self action:@selector(selectAction) forControlEvents:UIControlEventTouchUpInside]; } return _selectedBtn; } - (UILabel *)qrImgLabel { if (!_qrImgLabel) { _qrImgLabel = [[UILabel alloc] init]; _qrImgLabel.backgroundColor = [UIColor YHColorWithHex:0xFF891A]; _qrImgLabel.textColor = [UIColor whiteColor]; _qrImgLabel.textAlignment = NSTextAlignmentCenter; _qrImgLabel.font = [UIFont systemFontOfSize:13]; _qrImgLabel.text = @"二维码推广图"; } return _qrImgLabel; } @end