天天省钱快报

AdPopView.m 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //
  2. // AdPopView.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/5/31.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "AdPopView.h"
  9. @interface AdPopView (){
  10. AdPopModel *_model;
  11. }
  12. @property (nonatomic, strong) UIView *bgView;
  13. @property (nonatomic, strong) UIImageView *imgView;
  14. @property (nonatomic, strong) UIButton *closeButton;
  15. @end
  16. @implementation AdPopView
  17. - (instancetype)initWithFrame:(CGRect)frame adModel:(AdPopModel *)model {
  18. self = [super initWithFrame:frame];
  19. if (self) {
  20. _model = model;
  21. [self initSubViews];
  22. }
  23. return self;
  24. }
  25. - (void)initSubViews {
  26. [self addSubview:self.imgView];
  27. [self.imgView addSubview:self.closeButton];
  28. self.imgView.frame = self.bounds;
  29. self.closeButton.frame = CGRectMake(self.imgView.width-10-34, 0, 34, 34);
  30. [self.imgView sd_setImageWithURL:[NSURL URLWithString:_model.img]];
  31. }
  32. - (void)tapImageView {
  33. if (self.clickBlock) {
  34. self.clickBlock(_model);
  35. }
  36. }
  37. - (void)closeAction {
  38. if (self.closeBlock) {
  39. self.closeBlock();
  40. }
  41. }
  42. #pragma mark -------
  43. - (UIImageView *)imgView {
  44. if (!_imgView) {
  45. _imgView = [[UIImageView alloc] init];
  46. _imgView.userInteractionEnabled = YES;
  47. _imgView.backgroundColor = [UIColor clearColor];
  48. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapImageView)];
  49. [_imgView addGestureRecognizer:tap];
  50. }
  51. return _imgView;
  52. }
  53. - (UIView *)bgView {
  54. if (!_bgView) {
  55. _bgView = [[UIView alloc] init];
  56. _bgView.backgroundColor = [UIColor clearColor];
  57. }
  58. return _bgView;
  59. }
  60. - (UIButton *)closeButton {
  61. if (!_closeButton) {
  62. _closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
  63. [_closeButton setImage:[UIImage imageNamed:@"popViewSources.bundle/ad_close"] forState:UIControlStateNormal];
  64. [_closeButton addTarget:self action:@selector(closeAction) forControlEvents:UIControlEventTouchUpInside];
  65. }
  66. return _closeButton;
  67. }
  68. @end