口袋优选

KBMineAdView.m 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 clearColor];
  19. self.layer.cornerRadius = 6;
  20. self.clipsToBounds = YES;
  21. self.autoresizingMask = YES;
  22. [self initSubViews];
  23. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)];
  24. [self addGestureRecognizer:tap];
  25. }
  26. return self;
  27. }
  28. - (void)initSubViews {
  29. _imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.width, self.height-10)];
  30. _imageView.userInteractionEnabled = YES;
  31. _imageView.layer.cornerRadius = 6;
  32. _imageView.clipsToBounds = YES;
  33. _imageView.layer.masksToBounds = YES;
  34. _imageView.width = self.width;
  35. _imageView.centerX = self.width/2;
  36. _imageView.backgroundColor = [UIColor whiteColor];
  37. _imageView.contentMode = UIViewContentModeScaleAspectFill;
  38. [self addSubview:_imageView];
  39. [_imageView mas_makeConstraints:^(MASConstraintMaker *make) {
  40. make.left.top.right.mas_equalTo(0);
  41. make.bottom.mas_equalTo(-10);
  42. }];
  43. // UIButton *close = [[UIButton alloc] initWithFrame:CGRectMake(self.width-30-5, 0, 30, 30)];
  44. // close.centerY = _imageView.centerY;
  45. // [close setImage:[UIImage imageNamed:@"close_ad"] forState:UIControlStateNormal];
  46. // [close addTarget:self action:@selector(closeAction) forControlEvents:UIControlEventTouchUpInside];
  47. // [self addSubview:close];
  48. }
  49. - (void)setModel:(AdPopModel *)model {
  50. _model = model;
  51. [_imageView sd_setImageWithURL:[NSURL URLWithString:model.img] placeholderImage:nil];
  52. }
  53. - (void)tapAction {
  54. if (self.tapAdBlock) {
  55. self.tapAdBlock(_model);
  56. }
  57. }
  58. - (void)closeAction {
  59. if (self.closeBlock) {
  60. self.closeBlock();
  61. }
  62. }
  63. @end