MajorCommentCell.m 3.5 KB
//
//  MajorCommentCell.m
//  DreamSleep
//
//  Created by peter on 2022/10/9.
//

#import "MajorCommentCell.h"

@interface MajorCommentCell ()
@property (nonatomic, strong) UIImageView *userIcon;
@property (nonatomic, strong) UILabel *userNameLab;
@property (nonatomic, strong) UILabel *timeLab;
@property (nonatomic, strong) UILabel *commentContentLab;
@end

@implementation MajorCommentCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.dk_backgroundColorPicker = DKColorPickerWithColors(DSWhite, DarkColor, DSWhite);
        
        [self.contentView addSubview:self.userIcon];
        [self.contentView addSubview:self.userNameLab];
        [self.contentView addSubview:self.timeLab];
        [self.contentView addSubview:self.commentContentLab];
        
        [self.userIcon mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(30);
            make.top.equalTo(self.contentView).offset(15);
            make.size.mas_equalTo(CGSizeMake(40, 40));
        }];
        [self.userNameLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.userIcon.mas_right).offset(14);
            make.top.equalTo(self.userIcon);
            make.right.equalTo(self.contentView).offset(-30);
        }];
        [self.timeLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.userNameLab);
            make.bottom.equalTo(self.userIcon);
        }];
    }
    return self;
}

- (void)setCommentModel:(CommentModel *)commentModel {
    _commentModel = commentModel;
    
    [self.userIcon yy_setImageWithURL:[NSURL URLWithString:commentModel.user_profile] placeholder:[UIImage defaultPlaceholderWithSize:CGSizeMake(40, 40)]];
    self.userNameLab.text = commentModel.nick_name;
    self.timeLab.text = commentModel.publish_time;
    self.commentContentLab.text = commentModel.content;
    
    [self.commentContentLab mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.userIcon.mas_bottom).offset(12);
        make.left.equalTo(self.contentView).offset(kContentMargin);
        make.right.equalTo(self.contentView).offset(-kContentMargin);
        make.height.equalTo(@([commentModel commentContentHeight]));
    }];
}

#pragma mark - lazy
- (UIImageView *)userIcon {
    if (!_userIcon) {
        _userIcon = [UIImageView new];
        [_userIcon cornerRadius:20];
        _userIcon.dk_alphaPicker = DKAlphaPickerWithAlphas(1.f, 0.5f, 0.1f);
    }
    return _userIcon;
}

- (UILabel *)userNameLab {
    if (!_userNameLab) {
        _userNameLab = [UILabel labWithFont:BoldFont(15)];
        _userNameLab.dk_textColorPicker = DKColorPickerWithColors(MainTextColor, DkTitleColor, DSWhite);
    }
    return _userNameLab;
}

- (UILabel *)timeLab {
    if (!_timeLab) {
        _timeLab = [UILabel labWithFont:SysFont(12)];
        _timeLab.dk_textColorPicker = DKColorPickerWithColors(SmallTextColor, ColorFromHexA(0xFFFFFF, .3), DSWhite);
    }
    return _timeLab;
}

- (UILabel *)commentContentLab {
    if (!_commentContentLab) {
        _commentContentLab = [UILabel labWithFont:[CommentModel commentContentFont]];
        _commentContentLab.dk_textColorPicker = DKColorPickerWithColors(MainTextColor, ColorFromHexA(0xFFFFFF, .5), DSWhite);
        _commentContentLab.numberOfLines = 0;
    }
    return _commentContentLab;
}

@end