口袋优选

KBChildPageAdView.m 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. //
  2. // KBChildPageAdView.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/10/16.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "KBChildPageAdView.h"
  9. @interface KBChildPageAdView ()
  10. @property (nonatomic, strong) UIImageView *imgView;
  11. @end
  12. @implementation KBChildPageAdView
  13. - (instancetype)initWithFrame:(CGRect)frame
  14. {
  15. self = [super initWithFrame:frame];
  16. if (self) {
  17. self.clipsToBounds = YES;
  18. self.backgroundColor = [UIColor whiteColor];
  19. self.layer.cornerRadius = Fitsize(8);
  20. self.imgView = [[UIImageView alloc] initWithFrame:self.bounds];
  21. self.imgView.clipsToBounds = YES;
  22. self.imgView.userInteractionEnabled = YES;
  23. self.imgView.contentMode = UIViewContentModeScaleAspectFill;
  24. [self addSubview:self.imgView];
  25. self.autoresizingMask = YES;
  26. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAdAction)];
  27. [self.imgView addGestureRecognizer:tap];
  28. self.imgView.autoresizingMask = UIViewAutoresizingFlexibleWidth |
  29. UIViewAutoresizingFlexibleHeight;
  30. }
  31. return self;
  32. }
  33. - (void)tapAdAction {
  34. if (self.tapAdBlock) {
  35. self.tapAdBlock(self.adModel);
  36. }
  37. }
  38. - (void)setAdModel:(AdPopModel *)adModel {
  39. _adModel = adModel;
  40. [self.imgView sd_setImageWithURL:[NSURL URLWithString:adModel.img]];
  41. }
  42. @end