// // 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 whiteColor]; self.layer.cornerRadius = 6; self.clipsToBounds = YES; [self initSubViews]; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)]; [self addGestureRecognizer:tap]; } return self; } - (void)initSubViews { CGFloat width = SCREEN_MUTI > 1? 314 : Fitsize(314); CGFloat height = SCREEN_MUTI > 1? 72 : Fitsize(72); _imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, width, height)]; _imageView.userInteractionEnabled = YES; _imageView.clipsToBounds = YES; _imageView.layer.masksToBounds = YES; _imageView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin; _imageView.centerX = self.width/2; _imageView.backgroundColor = [UIColor clearColor]; _imageView.contentMode = UIViewContentModeScaleAspectFit; [self addSubview:_imageView]; 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