PraiseCell.m 3.7 KB
//
//  PraiseCell.m
//  DreamSleep
//
//  Created by peter on 2022/10/11.
//

#import "PraiseCell.h"

@interface PraiseCell ()
@property (nonatomic, strong) UIImageView *userIcon;
@property (nonatomic, strong) UILabel *userNameLab;
@property (nonatomic, strong) UILabel *timeLab;
@property (nonatomic, strong) UILabel *tipLab;
@property (nonatomic, strong) UILabel *contentLab;
@end

@implementation PraiseCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self.contentView addSubview:self.userIcon];
        [self.contentView addSubview:self.userNameLab];
        [self.contentView addSubview:self.timeLab];
        [self.contentView addSubview:self.tipLab];
        [self.contentView addSubview:self.contentLab];
        
        [self.userIcon mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(15);
            make.top.equalTo(self.contentView).offset(15);
            make.size.mas_equalTo(CGSizeMake(40, 40));
        }];
        [self.timeLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView).offset(18);
            make.right.equalTo(self.contentView).offset(-15);
        }];
        [self.tipLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.userNameLab);
            make.bottom.equalTo(self.userIcon);
        }];
        [self.contentLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.userIcon.mas_bottom).offset(7);
            make.left.equalTo(self.contentView).offset(73);
            make.right.equalTo(self.contentView).offset(-50);
        }];
    }
    return self;
}

- (void)setPraiseModel:(PraiseModel *)praiseModel {
    _praiseModel = praiseModel;
    
    [self.userIcon yy_setImageWithURL:[NSURL URLWithString:praiseModel.user_profile] placeholder:[UIImage defaultPlaceholderWithSize:CGSizeMake(40, 40)]];
    self.userNameLab.text = praiseModel.nick_name;
    self.timeLab.text = praiseModel.publish_time;
    [self.timeLab sizeToFit];
    self.contentLab.text = praiseModel.content;
    
    [self.userNameLab mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.userIcon.mas_right).offset(12);
        make.top.equalTo(self.userIcon);
        make.right.equalTo(self.timeLab.mas_left).offset(-30);
    }];
}

#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 = DKColorPickerWithKey(Dk_TITLE);
    }
    return _userNameLab;
}

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

- (UILabel *)tipLab {
    if (!_tipLab) {
        _tipLab = [UILabel labWithFont:SysFont(12)];
        _tipLab.text = @"赞了你的动态";
        _tipLab.dk_textColorPicker = DKColorPickerWithColors(SmallTextColor, ColorFromHexA(0xFFFFFF, .3), DSWhite);
    }
    return _tipLab;
}

- (UILabel *)contentLab {
    if (!_contentLab) {
        _contentLab = [UILabel labWithFont:SysFont(14)];
        _contentLab.dk_textColorPicker = DKColorPickerWithColors(SmallTextColor, ColorFromHexA(0xFFFFFF, .4), DSWhite);
    }
    return _contentLab;
}

@end