//
//  SelectedImg.m
//  Open
//
//  Created by 雷俊博 on 2020/4/7.
//  Copyright © 2020 黄江涛 . All rights reserved.
//

#import "SelectedImg.h"

@interface SelectedImg ()


@property (nonatomic, strong)UIImageView* selectIcon;

@end

@implementation SelectedImg
#pragma mark - life style
- (instancetype)initCustomUI
{
    self = [super init];
    if (self) {
        self.backgroundColor = [UIColor redColor];
        self.userInteractionEnabled = YES;
        
        
        
        [self configUI];
    }
    return self;
}

- (void)configUI
{
   
    [self addSubview:self.selectIcon];
    
    [self configData];
    
    [self.selectIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.bottom.right.offset(0);
    }];
    
    UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapClick:)];
    [self addGestureRecognizer:tap];
}

- (void)configData
{
    _isSelected = NO;
    self.selectIcon.hidden = YES;
}


#pragma mark - event response
- (void)tapClick:(UITapGestureRecognizer *)tap
{
    _isSelected = !_isSelected;
    
    if (_isSelected) {
        self.selectIcon.hidden = NO;
    }else{
        self.selectIcon.hidden = YES;
    }
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(clickImg:)]) {
        [self.delegate clickImg:self];
    }
    
}

#pragma mark - getters and setters


- (UIImageView *)selectIcon
{
    if (!_selectIcon) {
        _selectIcon = [[UIImageView alloc]init];
        _selectIcon.image = [UIImage imageNamed:@"ImageCover-10"];
    }
    return _selectIcon;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
