CNWitnessSearchCell.m 2.36 KB
//
//  CNWitnessSearchCell.m
//  CNLiveVideoClassifyKit
//
//  Created by CNLive on 2022/6/16.
//

#import "CNWitnessSearchCell.h"
@interface CNWitnessSearchCell()
@property (nonatomic, strong)UILabel *textLabel;
@property (nonatomic, strong)UIView *lineView;
@property (nonatomic, strong)UIButton *delectBtn;
@end

@implementation CNWitnessSearchCell
- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self.contentView addSubview:self.textLabel];
        [self.contentView addSubview:self.lineView];
        [self.contentView addSubview:self.delectBtn];
        [self.textLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.left.equalTo(self);
            make.right.equalTo(self.delectBtn.mas_left);
        }];
        [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.bottom.left.equalTo(self);
            make.height.mas_equalTo(0.5);
        }];
        [self.delectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.centerY.equalTo(self);
            make.width.height.mas_equalTo(11.5);
        }];
    }
    return self;
}
- (void)deleteBtnClick{
    if (self.deleteBlock) {
        self.deleteBlock(self.textLabel.text);
    }
}
- (void)setString:(NSString *)str section:(NSInteger)section{
    self.textLabel.text = str;
    if (section == 0) {
        self.lineView.hidden = NO;
        self.delectBtn.hidden = NO;
    }else{
        self.lineView.hidden = YES;
        self.delectBtn.hidden = YES;
    }
}
#pragma mark - Getting
- (UILabel *)textLabel
{
    if (!_textLabel) {
        _textLabel = [[UILabel alloc] init];
        _textLabel.font = UIFontMake(14);
        _textLabel.textColor = UIColorHex(#333333);
        _textLabel.textAlignment = NSTextAlignmentLeft;
    }
    return _textLabel;
}
- (UIView *)lineView{
    if (!_lineView) {
        _lineView = [[UIView alloc] init];
        _lineView.backgroundColor = UIColorHex(#F2F2F2);
    }
    return _lineView;
}
- (UIButton *)delectBtn{
    if (!_delectBtn) {
        _delectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_delectBtn setImage:[UIImage loadBundleImage:@"witness_history_delete"] forState:UIControlStateNormal];
        [_delectBtn addTarget:self action:@selector(deleteBtnClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _delectBtn;
}
@end