CNLiveFontSettingCell.m 2.67 KB
//
//  CNLiveFontSettingCell.m
//  CNLiveSettingModule
//
//  Created by 153993236@qq.com on 11/12/2019.
//  Copyright (c) 2019 153993236@qq.com. All rights reserved.
//

#import "CNLiveFontSettingCell.h"
#import <SDWebImage/SDWebImage.h>

#import "CNLiveBaseKit.h"
#import "CNLiveCategory.h"

#import "CNLiveFontSettingModel.h"
#import "CNLiveFontSettingFrame.h"
#import "CNLiveFontSettingContentButton.h"

@interface CNLiveFontSettingCell()
@property (nonatomic, strong) UIImageView *headImage;//头像
@property (nonatomic, strong) CNLiveFontSettingContentButton *btnContent;//显示内容

@end

@implementation CNLiveFontSettingCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.headImage = [[UIImageView alloc]init];
        _headImage.backgroundColor = [UIColor clearColor];
        _headImage.layer.masksToBounds = YES;
        _headImage.layer.cornerRadius = 3;
        [self.contentView addSubview:self.headImage];
        
        self.btnContent = [[CNLiveFontSettingContentButton alloc]init];
        [self.contentView addSubview:self.btnContent];

    }
    return self;
}

#pragma mark - 内容及Frame设置
- (void)setFontSettingFrame:(CNLiveFontSettingFrame *)fontSettingFrame{
    _fontSettingFrame = fontSettingFrame;
    CNLiveFontSettingModel *model = fontSettingFrame.model;

    // 1.设置头像
    self.headImage.frame = fontSettingFrame.iconFrame;
    UIImage *image = [UIImage cn_getImageName:@"font_size_logo" bundleName:@"CNLiveSettingModule" targetClass:[self class]];
    [_headImage sd_setImageWithURL:[NSURL URLWithString:model.icon] placeholderImage:image];
    
    // 2.设置内容
    self.btnContent.fontSettingFrame = fontSettingFrame;//这里设置内容的frame等
    
}

/**
 *  创建图片
 *
 *  @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