ReadyItemCell.m 1.7 KB
//
//  ReadyItemCell.m
//  DreamSleep
//
//  Created by peter on 2022/7/14.
//

#import "ReadyItemCell.h"

@interface ReadyItemCell ()
@property (nonatomic, strong) UIImageView *icon;
@property (nonatomic, strong) UILabel *timeLab;
@property (nonatomic, strong) UILabel *nameLab;
@end

@implementation ReadyItemCell

- (instancetype)initWithFrame:(CGRect)frame itemCellType:(ItemCellType)type {
    if (self = [super initWithFrame:frame]) {
        [self addSubview:self.icon];
        [self addSubview:self.timeLab];
        if (type == ItemCellTypeStart) {
            [self addSubview:self.nameLab];
        }
        
        [self.icon mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.right.equalTo(self);
            make.width.height.equalTo(@40);
        }];
        [self.timeLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.left.right.equalTo(self);
        }];
    }
    return self;
}

- (void)setItem:(ReadyItem *)item {
    _item = item;
    [self.icon yy_setImageWithURL:[NSURL URLWithString:item.icon] options:YYWebImageOptionShowNetworkActivity];
    self.timeLab.text = [NSString stringWithFormat:@"%dmin", item.time];
}

- (void)adjustTime {
    self.timeLab.text = [NSString stringWithFormat:@"%dmin", self.item.time];
}

#pragma mark - lazy
- (UIImageView *)icon {
    if (!_icon) {
        _icon = [UIImageView new];
    }
    return _icon;
}

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

@end