cdts/xdts-ios 3/TreeHole/Code/Features/Bottle/View/BottleCollectionCell.m
2023-07-27 09:20:00 +08:00

84 lines
2.7 KiB
Objective-C

//
// BottleCollectionCell.m
// TreeHole
//
// Created by mambaxie on 2022/4/27.
//
#import "BottleCollectionCell.h"
NSString *BottleCollectionCellReuseID = @"BottleCollectionCellReuseID";
CGFloat BottleCollectionCellWidth = 75;
CGFloat BottleCollectionCellHeight = 80;
@interface BottleCollectionCell()
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UIImageView *coverImageView;
@end
@implementation BottleCollectionCell
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
[self setupUI];
}
return self;
}
- (void)setupUI {
self.backgroundColor = [UIColor clearColor];
self.width = FIX_SIZE(BottleCollectionCellWidth);
self.height = FIX_SIZE(BottleCollectionCellHeight);
self.contentView.clipsToBounds = YES;
UIView *leftView = [[UIView alloc] init];
leftView.backgroundColor = COLOR_WITH_RGB(0x403D56);
leftView.width = FIX_SIZE(2);
leftView.y = -1;
leftView.height = self.height + 2;
[self.contentView addSubview:leftView];
UIImageView *backgroundImageView = [[UIImageView alloc] init];
backgroundImageView.x = leftView.right;
backgroundImageView.width = self.width - backgroundImageView.x;
backgroundImageView.height = self.height;
backgroundImageView.image = ImageNamed(@"TH_home_light_bg");
backgroundImageView.backgroundColor = [UIColor clearColor];
[self.contentView addSubview:backgroundImageView];
UILabel *contentLabel = [[UILabel alloc] init];
contentLabel.frame = backgroundImageView.frame;
contentLabel.y = FIX_SIZE(7);
contentLabel.height = FIX_SIZE(70);
contentLabel.backgroundColor = [UIColor clearColor];
contentLabel.textAlignment = NSTextAlignmentCenter;
contentLabel.textColor = COLOR_WITH_RGB_A(0xFFFFFF, 0.3);
contentLabel.numberOfLines = 2;
contentLabel.font = MT_FONT_ALIBABA_SIZE(20);
// contentLabel.adjustsFontSizeToFitWidth = YES;
[self.contentView addSubview:contentLabel];
self.nameLabel = contentLabel;
UIImageView *bottleImageView = [[UIImageView alloc] init];
bottleImageView.frame = backgroundImageView.frame;
bottleImageView.backgroundColor = [UIColor clearColor];
bottleImageView.contentMode = UIViewContentModeScaleAspectFill;
bottleImageView.bottom = self.height;
[self.contentView addSubview:bottleImageView];
self.coverImageView = bottleImageView;
[self.contentView bringSubviewToFront:leftView];
}
- (void)setInfo:(BottleInfo *)info {
_info = info;
self.nameLabel.text = [NSString stringWithFormat:@"%@", info.typeInfo.bottle_type_name];
[self.coverImageView sd_setImageWithURL:[NSURL URLWithString:info.cover ?: @""]];
}
@end