ApplyForShootCell.m 6.25 KB

//
//  ApplyForShootCell.m
//  com.cnlive.pro.CNLiveNetAdd
//
//  Created by cnliveJunBo on 2018/4/12.
//  Copyright © 2018年 cnlive. All rights reserved.
//

#import "ApplyForShootCell.h"
#import <Masonry/Masonry.h>
#import "CNLiveBaseKit.h"
#import <QMUIKit/QMUIKit.h>
#import "CNLiveIDCardAuthGetImage.h"
@interface ApplyForShootCell ()

@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UILabel *subTitleLab;
@property (nonatomic, strong) UIButton *shootBtn;
@property (nonatomic, strong) UIView *lineV;

@end

@implementation ApplyForShootCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupUI];
    }
    return self;
}

- (void)setModel:(AgreementModel *)model {
    
    _titleLab.text = model.shootTitle;
    _imgV.image = [CNLiveIDCardAuthGetImage cnLiveIDCardAuth_getImageName:model.shootImage bundle:@"CNBPersonCardInfo.bundle/CNBPersonCardInfo" targetClass:[self class]];
    if (model.isFront) {
        self.lineV.hidden = NO;
        NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"请拍摄本人身份证正面 注意避免证件反光"];
        NSRange range1 = [[str string] rangeOfString:@"请拍摄本人身份证"];
        [str addAttribute:NSForegroundColorAttributeName value:RGBA(156, 156, 156, 1) range:range1];
        NSRange range2 = [[str string] rangeOfString:@"正面"];
        [str addAttribute:NSForegroundColorAttributeName value:RGBA(255, 59, 48, 1) range:range2];
        NSRange range3 = [[str string] rangeOfString:@" 注意避免证件反光"];
        [str addAttribute:NSForegroundColorAttributeName value:RGBA(156, 156, 156, 1) range:range3];
        _subTitleLab.attributedText = str;
    } else {
        self.lineV.hidden = YES;
        NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"请拍摄本人身份证反面 注意避免证件反光"];
        NSRange range1 = [[str string] rangeOfString:@"请拍摄本人身份证"];
        [str addAttribute:NSForegroundColorAttributeName value:RGBA(156, 156, 156, 1) range:range1];
        NSRange range2 = [[str string] rangeOfString:@"反面"];
        [str addAttribute:NSForegroundColorAttributeName value:RGBA(255, 59, 48, 1) range:range2];
        NSRange range3 = [[str string] rangeOfString:@" 注意避免证件反光"];
        [str addAttribute:NSForegroundColorAttributeName value:RGBA(156, 156, 156, 1) range:range3];
        _subTitleLab.attributedText = str;
    }

}

- (void)setupUI {
    
    [self.contentView addSubview:self.lineV];
    [self.contentView addSubview:self.titleLab];
    [self.contentView addSubview:self.subTitleLab];
    [self.contentView addSubview:self.imgV];
//    [self.imgV addSubview:self.shootBtn];
    
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    [self.lineV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.equalTo(self.contentView);
        make.height.mas_equalTo(1);
    }];
    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(69);
        make.top.equalTo(_lineV.mas_bottom).offset(22);
        make.width.mas_equalTo(64);
        make.height.mas_equalTo(16);
    }];
    [self.subTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.contentView);
        make.top.equalTo(self.titleLab.mas_bottom).offset(15);
        make.width.mas_equalTo(245);
        make.height.mas_equalTo(15);
    }];
    CGFloat width = KScreenWidth - 88;
    CGFloat height = width*157.0/287.0;
    [self.imgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.subTitleLab.mas_bottom).offset(10);
        make.left.equalTo(self).offset(44);
        make.right.equalTo(self).offset(-44);
        make.height.mas_equalTo(height);
    }];
//    [self.shootBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.center.equalTo(self.imgV);
//        make.width.height.mas_equalTo(60);
//    }];
}

- (void)shootPhotoAction:(UIButton *)sender{
    if (self.clickShootBtnBlock) {
        self.clickShootBtnBlock();
    }
}

- (void)shootPhoto:(UITapGestureRecognizer *)tap {
    if (self.clickShootBtnBlock) {
        self.clickShootBtnBlock();
    }
}

#pragma mark - SubViews
- (UILabel *)titleLab {
    if (!_titleLab) {
        _titleLab = [[UILabel alloc] init];
        _titleLab.textColor = RGB(26, 26, 26);
        _titleLab.font = [UIFont systemFontOfSize:16];
    }
    return _titleLab;
}

- (UILabel *)subTitleLab {
    if (!_subTitleLab) {
        _subTitleLab = [[UILabel alloc] init];
        _subTitleLab.textColor = RGB(156, 156, 156);
        _subTitleLab.font = [UIFont systemFontOfSize:12];
    }
    return _subTitleLab;
}

- (UIImageView *)imgV {
    if (!_imgV) {
        _imgV = [[UIImageView alloc] init];
        _imgV.contentMode = UIViewContentModeScaleToFill;
        _imgV.userInteractionEnabled = YES;
//        _imgV.layer.borderWidth = 1.0f;
//        _imgV.layer.borderColor = RGB(232, 232, 232).CGColor;
//        _imgV.layer.cornerRadius = 6.0f;
//        _imgV.layer.masksToBounds = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(shootPhoto:)];
        [_imgV addGestureRecognizer:tap];
    }
    return _imgV;
}

- (UIButton *)shootBtn {
    if (!_shootBtn) {
        _shootBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_shootBtn setImage:[CNLiveIDCardAuthGetImage cnLiveIDCardAuth_getImageName:@"dl_xiangji" bundle:@"CNBPersonCardInfo.bundle/CNLiveBPersonalVerificationModule" targetClass:[self class]] forState:UIControlStateNormal];
        [_shootBtn addTarget:self action:@selector(shootPhotoAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _shootBtn;
}

- (UIView *)lineV {
    if (!_lineV) {
        _lineV = [[UIView alloc] init];
        _lineV.backgroundColor = RGB(238, 238, 238);
    }
    return _lineV;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end