ASHomeImgCell.m 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //
  2. // ASHomeImgCell.m
  3. // Asteria
  4. //
  5. // Created by iOS on 2023/6/10.
  6. //
  7. #import "ASHomeImgCell.h"
  8. @interface ASHomeImgCell ()
  9. @property (nonatomic, strong) UIImageView *imgV;
  10. @property (nonatomic, strong) UIButton *bt;
  11. @end
  12. @implementation ASHomeImgCell
  13. - (void)setImgStr:(NSString *)imgStr {
  14. [self.imgV sd_setImageWithURL:[NSURL URLWithString:imgStr] placeholderImage:[UIImage imageNamed:@"product_defualtImg"]];
  15. }
  16. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  17. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  18. if (self) {
  19. [self loadSubV];
  20. }
  21. return self;
  22. }
  23. - (void)loadSubV {
  24. self.selectionStyle = UITableViewCellSelectionStyleNone;
  25. self.backgroundColor = _0E0E0F;
  26. [self.contentView addSubview:self.imgV];
  27. [self.imgV mas_makeConstraints:^(MASConstraintMaker *make) {
  28. make.edges.equalTo(self.contentView);
  29. make.width.equalTo(self.imgV.mas_height).multipliedBy(375.0/200);
  30. }];
  31. [self.contentView addSubview:self.bt];
  32. [self.bt mas_makeConstraints:^(MASConstraintMaker *make) {
  33. make.edges.equalTo(self.contentView);
  34. }];
  35. }
  36. - (void)awakeFromNib {
  37. [super awakeFromNib];
  38. // Initialization code
  39. }
  40. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  41. [super setSelected:selected animated:animated];
  42. // Configure the view for the selected state
  43. }
  44. - (UIImageView *)imgV {
  45. if (!_imgV) {
  46. UIImageView *v = [UIImageView baseImgV];
  47. v.contentMode = UIViewContentModeScaleAspectFill;
  48. v.clipsToBounds = true;
  49. _imgV = v;
  50. }
  51. return _imgV;
  52. }
  53. - (UIButton *)bt {
  54. if (!_bt) {
  55. UIButton *b = [UIButton buttonWithType:UIButtonTypeCustom];
  56. [b addTarget:self action:@selector(btAction) forControlEvents:UIControlEventTouchUpInside];
  57. _bt = b;
  58. }
  59. return _bt;
  60. }
  61. - (void)btAction {
  62. if (self.tapImgBlock) {
  63. self.tapImgBlock();
  64. }
  65. }
  66. @end