MessageOfficialNotiCell.m 3.4 KB
//
//  MessageOfficialNotiCell.m
//  DreamSleep
//
//  Created by peter on 2022/10/10.
//

#import "MessageOfficialNotiCell.h"

@interface MessageOfficialNotiCell ()
@property (nonatomic, strong) UIImageView *icon;
@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UILabel *detailLab;
@property (nonatomic, strong) UILabel *mesCountLab;
@end

@implementation MessageOfficialNotiCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = DSClearColor;
        
        [self.contentView addSubview:self.icon];
        [self.contentView addSubview:self.titleLab];
        [self.contentView addSubview:self.detailLab];
        [self.contentView addSubview:self.mesCountLab];
        
        [self.icon mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(15);
            make.top.equalTo(self.contentView).offset(18);
            make.size.mas_equalTo(CGSizeMake(40, 40));
        }];
        [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.icon.mas_right).offset(12);
            make.top.equalTo(self.icon);
            make.right.equalTo(self.contentView).offset(-50);
        }];
        [self.detailLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.titleLab);
            make.bottom.equalTo(self.icon);
            make.right.equalTo(self.titleLab);
        }];
        [self.mesCountLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.contentView);
            make.right.equalTo(self.contentView).offset(-15);
            make.size.mas_equalTo(CGSizeMake(20, 20));
        }];
    }
    return self;
}

- (void)setOfficialModel:(MessageOfficialModel *)officialModel {
    _officialModel = officialModel;
    
    [self.icon yy_setImageWithURL:[NSURL URLWithString:officialModel.iconName] placeholder:[UIImage defaultPlaceholderWithSize:CGSizeMake(40, 40)]];
    self.titleLab.text = officialModel.title;
    self.mesCountLab.hidden = !officialModel.messageCount;
    self.mesCountLab.text = [NSString stringWithFormat:@"%d", officialModel.messageCount];
    self.detailLab.text = self.mesCountLab.hidden == NO ? officialModel.detail : (officialModel.isPraise ? @"暂无点赞" : @"暂无通知");
}

#pragma mark - lazy
- (UIImageView *)icon {
    if (!_icon) {
        _icon = [UIImageView new];
        _icon.dk_alphaPicker = DKAlphaPickerWithAlphas(1, .5, .5);
        [_icon cornerRadius:20];
    }
    return _icon;
}

- (UILabel *)titleLab {
    if (!_titleLab) {
        _titleLab = [UILabel labWithFont:BoldFont(15)];
        _titleLab.dk_textColorPicker = DKColorPickerWithKey(Dk_TITLE);
    }
    return _titleLab;
}

- (UILabel *)detailLab {
    if (!_detailLab) {
        _detailLab = [UILabel labWithFont:SysFont(14)];
        _detailLab.dk_textColorPicker = DKColorPickerWithColors(SubTitleColor, ColorFromHexA(0xFFFFFF, .5), DSWhite);
    }
    return _detailLab;
}

- (UILabel *)mesCountLab {
    if (!_mesCountLab) {
        _mesCountLab = [UILabel labWithTextColor:DSWhite font:SysFont(12)];
        _mesCountLab.backgroundColor = ColorFromHex(0xF04B77);
        _mesCountLab.textAlignment = NSTextAlignmentCenter;
        [_mesCountLab cornerRadius:10];
    }
    return _mesCountLab;
}

@end