123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- //
- // AdPopView.m
- // YouHuiProject
- //
- // Created by 小花 on 2018/5/31.
- // Copyright © 2018年 kuxuan. All rights reserved.
- //
- #import "AdPopView.h"
- @interface AdPopView (){
- AdPopModel *_model;
- }
- @property (nonatomic, strong) UIView *bgView;
- @property (nonatomic, strong) UIImageView *imgView;
- @property (nonatomic, strong) UIButton *closeButton;
- @end
- @implementation AdPopView
- - (instancetype)initWithFrame:(CGRect)frame adModel:(AdPopModel *)model {
- self = [super initWithFrame:frame];
- if (self) {
- _model = model;
- [self initSubViews];
- }
- return self;
- }
- - (void)initSubViews {
-
- [self addSubview:self.imgView];
- [self.imgView addSubview:self.closeButton];
-
- self.imgView.frame = self.bounds;
- self.closeButton.frame = CGRectMake(self.imgView.width-10-34, 0, 34, 34);
-
- [self.imgView sd_setImageWithURL:[NSURL URLWithString:_model.img]];
-
- }
- - (void)tapImageView {
- if (self.clickBlock) {
- self.clickBlock(_model);
- }
- }
- - (void)closeAction {
- if (self.closeBlock) {
- self.closeBlock();
- }
- }
- #pragma mark -------
- - (UIImageView *)imgView {
- if (!_imgView) {
- _imgView = [[UIImageView alloc] init];
- _imgView.userInteractionEnabled = YES;
- _imgView.backgroundColor = [UIColor clearColor];
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapImageView)];
- [_imgView addGestureRecognizer:tap];
- }
- return _imgView;
- }
- - (UIView *)bgView {
- if (!_bgView) {
- _bgView = [[UIView alloc] init];
- _bgView.backgroundColor = [UIColor clearColor];
- }
- return _bgView;
-
- }
- - (UIButton *)closeButton {
- if (!_closeButton) {
- _closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
- [_closeButton setImage:[UIImage imageNamed:@"popViewSources.bundle/ad_close"] forState:UIControlStateNormal];
- [_closeButton addTarget:self action:@selector(closeAction) forControlEvents:UIControlEventTouchUpInside];
- }
- return _closeButton;
- }
- @end
|