123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- //
- // 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 addSubview:self.closeButton];
-
- self.imgView.frame = CGRectMake(0, 0, Fitsize(250), Fitsize(350));
- self.imgView.center = CGPointMake(self.width/2, self.height/2);
- self.closeButton.frame = CGRectMake(0, 0, 34, 34);
- self.closeButton.top = self.imgView.bottom+10;
- self.closeButton.centerX = self.width/2;
- [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:@"close_white"] forState:UIControlStateNormal];
- [_closeButton addTarget:self action:@selector(closeAction) forControlEvents:UIControlEventTouchUpInside];
-
- }
- return _closeButton;
- }
- @end
|