口袋优选

AdPopView.m 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 addSubview:self.closeButton];
  28. self.imgView.frame = CGRectMake(0, 0, Fitsize(250), Fitsize(350));
  29. self.imgView.center = CGPointMake(self.width/2, self.height/2);
  30. self.closeButton.frame = CGRectMake(0, 0, 34, 34);
  31. self.closeButton.top = self.imgView.bottom+10;
  32. self.closeButton.centerX = self.width/2;
  33. [self.imgView sd_setImageWithURL:[NSURL URLWithString:_model.img]];
  34. }
  35. - (void)tapImageView {
  36. if (self.clickBlock) {
  37. self.clickBlock(_model);
  38. }
  39. }
  40. - (void)closeAction {
  41. if (self.closeBlock) {
  42. self.closeBlock();
  43. }
  44. }
  45. #pragma mark -------
  46. - (UIImageView *)imgView {
  47. if (!_imgView) {
  48. _imgView = [[UIImageView alloc] init];
  49. _imgView.userInteractionEnabled = YES;
  50. _imgView.backgroundColor = [UIColor clearColor];
  51. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapImageView)];
  52. [_imgView addGestureRecognizer:tap];
  53. }
  54. return _imgView;
  55. }
  56. - (UIView *)bgView {
  57. if (!_bgView) {
  58. _bgView = [[UIView alloc] init];
  59. _bgView.backgroundColor = [UIColor clearColor];
  60. }
  61. return _bgView;
  62. }
  63. - (UIButton *)closeButton {
  64. if (!_closeButton) {
  65. _closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
  66. [_closeButton setImage:[UIImage imageNamed:@"close_white"] forState:UIControlStateNormal];
  67. [_closeButton addTarget:self action:@selector(closeAction) forControlEvents:UIControlEventTouchUpInside];
  68. }
  69. return _closeButton;
  70. }
  71. @end