ScoreDetailCell.m 2.5 KB
//
//  ScoreDetailCell.m
//  DreamSleep
//
//  Created by peter on 2022/5/26.
//

#import "ScoreDetailCell.h"

@interface ScoreDetailCell ()
@property (nonatomic, strong) UILabel *itemNameLab;
@property (nonatomic, strong) UILabel *taskDateLab;
@property (nonatomic, strong) UILabel *pointsLab;
@end

@implementation ScoreDetailCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = DSClearColor;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.contentView addSubview:self.itemNameLab];
        [self.contentView addSubview:self.taskDateLab];
        [self.contentView addSubview:self.pointsLab];
    }
    return self;
}

- (void)setModel:(ScoreDetailModel *)model {
    _model = model;
    
    self.itemNameLab.text = model.item_name;
    self.taskDateLab.text = model.task_date;
    self.pointsLab.text = [NSString stringWithFormat:@"+%d", model.points];
    
    [self.itemNameLab sizeToFit];
    [self.taskDateLab sizeToFit];
    [self.pointsLab sizeToFit];
    
    [self.itemNameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(15);
        make.top.equalTo(self.contentView).offset(24);
    }];
    [self.taskDateLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.itemNameLab);
        make.top.equalTo(self.itemNameLab.mas_bottom).offset(8);
    }];
    [self.pointsLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.itemNameLab).offset(13);
        make.right.equalTo(self.contentView).offset(-15);
    }];
}

#pragma mark - lazy
- (UILabel *)itemNameLab {
    if (!_itemNameLab) {
        _itemNameLab = [UILabel labWithFont:BoldFont(15.0)];
        _itemNameLab.dk_textColorPicker = DKColorPickerWithKey(Dk_TITLE);
    }
    return _itemNameLab;
}

- (UILabel *)taskDateLab {
    if (!_taskDateLab) {
        _taskDateLab = [UILabel labWithFont:SysFont(12.0)];
        _taskDateLab.dk_textColorPicker = DKColorPickerWithColors(SmallTextColor, ColorFromHexA(0xFFFFFF, .3));
    }
    return _taskDateLab;
}

- (UILabel *)pointsLab {
    if (!_pointsLab) {
        _pointsLab = [UILabel labWithFont:SysFont(15.0)];
        _pointsLab.dk_textColorPicker = DKColorPickerWithKey(Dk_TITLE);
        _pointsLab.textAlignment = NSTextAlignmentRight;
    }
    return _pointsLab;
}

@end