1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- //
- // KBMineAdView.m
- // YouHuiProject
- //
- // Created by 小花 on 2018/6/6.
- // Copyright © 2018年 kuxuan. All rights reserved.
- //
- #import "KBMineAdView.h"
- @interface KBMineAdView ()
- {
- UIImageView *_imageView;
- }
- @end
- @implementation KBMineAdView
- - (instancetype)initWithFrame:(CGRect)frame {
- self = [super initWithFrame:frame];
- if (self) {
- self.backgroundColor = [UIColor clearColor];
- self.layer.cornerRadius = 6;
- self.clipsToBounds = YES;
- self.autoresizingMask = YES;
- [self initSubViews];
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)];
- [self addGestureRecognizer:tap];
- }
- return self;
- }
- - (void)initSubViews {
-
- _imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.width, self.height-10)];
- _imageView.userInteractionEnabled = YES;
- _imageView.layer.cornerRadius = 6;
- _imageView.clipsToBounds = YES;
- _imageView.layer.masksToBounds = YES;
- _imageView.width = self.width;
- _imageView.centerX = self.width/2;
- _imageView.backgroundColor = [UIColor whiteColor];
- _imageView.contentMode = UIViewContentModeScaleAspectFill;
- [self addSubview:_imageView];
- [_imageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.top.right.mas_equalTo(0);
- make.bottom.mas_equalTo(-10);
- }];
-
- // UIButton *close = [[UIButton alloc] initWithFrame:CGRectMake(self.width-30-5, 0, 30, 30)];
- // close.centerY = _imageView.centerY;
- // [close setImage:[UIImage imageNamed:@"close_ad"] forState:UIControlStateNormal];
- // [close addTarget:self action:@selector(closeAction) forControlEvents:UIControlEventTouchUpInside];
- // [self addSubview:close];
- }
- - (void)setModel:(AdPopModel *)model {
- _model = model;
- [_imageView sd_setImageWithURL:[NSURL URLWithString:model.img] placeholderImage:nil];
- }
- - (void)tapAction {
- if (self.tapAdBlock) {
- self.tapAdBlock(_model);
- }
- }
- - (void)closeAction {
- if (self.closeBlock) {
- self.closeBlock();
- }
- }
- @end
|