天天省钱快报

KBMineAdView.m 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //
  2. // KBMineAdView.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/6/6.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "KBMineAdView.h"
  9. @interface KBMineAdView ()
  10. {
  11. UIImageView *_imageView;
  12. }
  13. @end
  14. @implementation KBMineAdView
  15. - (instancetype)initWithFrame:(CGRect)frame {
  16. self = [super initWithFrame:frame];
  17. if (self) {
  18. self.backgroundColor = [UIColor whiteColor];
  19. self.layer.cornerRadius = 6;
  20. self.clipsToBounds = YES;
  21. [self initSubViews];
  22. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)];
  23. [self addGestureRecognizer:tap];
  24. }
  25. return self;
  26. }
  27. - (void)initSubViews {
  28. CGFloat width = SCREEN_MUTI > 1? 314 : Fitsize(314);
  29. CGFloat height = SCREEN_MUTI > 1? 72 : Fitsize(72);
  30. _imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, width, height)];
  31. _imageView.userInteractionEnabled = YES;
  32. _imageView.clipsToBounds = YES;
  33. _imageView.layer.masksToBounds = YES;
  34. _imageView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
  35. _imageView.centerX = self.width/2;
  36. _imageView.backgroundColor = [UIColor clearColor];
  37. _imageView.contentMode = UIViewContentModeScaleAspectFit;
  38. [self addSubview:_imageView];
  39. UIButton *close = [[UIButton alloc] initWithFrame:CGRectMake(self.width-30-5, 0, 30, 30)];
  40. close.centerY = _imageView.centerY;
  41. [close setImage:[UIImage imageNamed:@"close_ad"] forState:UIControlStateNormal];
  42. [close addTarget:self action:@selector(closeAction) forControlEvents:UIControlEventTouchUpInside];
  43. [self addSubview:close];
  44. }
  45. - (void)setModel:(AdPopModel *)model {
  46. _model = model;
  47. [_imageView sd_setImageWithURL:[NSURL URLWithString:model.img] placeholderImage:nil];
  48. }
  49. - (void)tapAction {
  50. if (self.tapAdBlock) {
  51. self.tapAdBlock(_model);
  52. }
  53. }
  54. - (void)closeAction {
  55. if (self.closeBlock) {
  56. self.closeBlock();
  57. }
  58. }
  59. @end