CNLiveInfoUpdateCell.m 3.93 KB
//
//  CNLiveInfoUpdateCell.m
//  CNLiveMineModule
//
//  Created by 153993236@qq.com on 11/12/2019.
//  Copyright (c) 2019 153993236@qq.com. All rights reserved.
//

#import "CNLiveInfoUpdateCell.h"
#import <Masonry/Masonry.h>
#import <SDWebImage/SDWebImage.h>
#import "CNLiveUserInfoModel.h"

@interface CNLiveInfoUpdateCell()
@property (nonatomic, strong) UIView *line;
@property (nonatomic, strong) UILabel *title;

@property (nonatomic, strong) UIImageView *pic;

@end

@implementation CNLiveInfoUpdateCell
static const NSInteger margin = 12;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.contentView.backgroundColor = [UIColor whiteColor];
        
        [self.contentView addSubview:self.title];
        [self.contentView addSubview:self.pic];
        [self.contentView addSubview:self.line];

        [self xw_layoutSubviews];
        
    }
    return self;
}

- (void)xw_layoutSubviews{
        
    [_title mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).with.offset(margin);
        make.top.equalTo(self.contentView.mas_top).with.offset(0);
        make.bottom.equalTo(self.contentView.mas_bottom).with.offset(0);

    }];
    
    [_pic mas_updateConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView.mas_right).with.offset(-margin);
        make.top.equalTo(self.contentView.mas_top).with.offset(0);
        make.bottom.equalTo(self.contentView.mas_bottom).with.offset(0);
        
    }];
    
    [_line mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).with.offset(0);
        make.right.equalTo(self.contentView.mas_right).with.offset(-0);
        make.bottom.equalTo(self.contentView.mas_bottom).with.offset(0);
        make.height.offset(0.5);
        
    }];

    
}

- (void)setText:(NSString *)text{
    _text = text;
    _title.text = text;
}

- (void)setIsShow:(BOOL)isShow{
    _isShow = isShow;
    _pic.hidden = !isShow;
}

- (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
}
#pragma mark - 懒加载
- (UIView *)line {
    if (!_line) {
        _line = [[UIView alloc] init];
        _line.backgroundColor = [UIColor colorWithRed:235/255.0 green:235/255.0 blue:235/255.0 alpha:1.0];
    }
    return _line;
}

- (UILabel *)title {
    if (!_title) {
        _title = [[UILabel alloc] init];
        _title.numberOfLines = 1;
        _title.textColor = [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0];
        _title.font = [UIFont systemFontOfSize:16];
    }
    return _title;
}


- (UIImageView *)pic {
    if (!_pic) {
        _pic = [[UIImageView alloc] init];
        UIImage *xw_image = [self xw_getImageName:@"mine_update_select" bundleName:@"CNLiveMineModule" targetClass:[self class]];
        _pic.image = xw_image;
        _pic.hidden = YES;
        _pic.contentMode = UIViewContentModeCenter;

    }
    return _pic;
}


/**
 *  创建图片
 *
 *  @param imageName 图片名字
 *  @param bundleName 图片所在的bundle名字
 *  @param targetClass 类和bundle的同级目录
 *  @return 返回UIImage
 */
- (UIImage *)xw_getImageName:(NSString *)imageName bundleName:(NSString *)bundleName targetClass:(Class)targetClass{
    NSBundle *bundle = [NSBundle bundleForClass:targetClass];
    NSURL *url = [bundle URLForResource:bundleName withExtension:@"bundle"];
    NSBundle *targetBundle = [NSBundle bundleWithURL:url];
    UIImage *image = [UIImage imageNamed:imageName inBundle:targetBundle compatibleWithTraitCollection:nil];
    return image?image:[UIImage imageNamed:imageName inBundle:[NSBundle mainBundle] compatibleWithTraitCollection:nil];
}

@end