Files
peko-ios/YuMi/Modules/YMMine/View/Cell/MineInfo/XPMineGiftsTableViewCell.m

182 lines
6.4 KiB
Mathematica
Raw Normal View History

2024-06-25 17:24:32 +08:00
//
// XPMineGiftsTableViewCell.m
// YuMi
//
// Created by P on 2024/6/25.
//
#import "XPMineGiftsTableViewCell.h"
#import "UserGiftWallInfoModel.h"
@interface XPMineGiftCell : UICollectionViewCell
@property (nonatomic, strong) UIImageView *backgroundImageView;
@property (nonatomic, strong) NetImageView *imageView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *countLabel;
@end
@implementation XPMineGiftCell
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self.contentView addSubview:self.backgroundImageView];
[self.backgroundImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.contentView);
}];
[self.contentView addSubview:self.imageView];
[self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.contentView);
make.top.mas_equalTo(12);
make.size.mas_equalTo(CGSizeMake(60, 60));
}];
[self.contentView addSubview:self.titleLabel];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.contentView);
make.top.mas_equalTo(self.imageView.mas_bottom).offset(10);
}];
[self.contentView addSubview:self.countLabel];
[self.countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.contentView);
make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(6);
}];
}
return self;
}
- (UIImageView *)backgroundImageView {
if (!_backgroundImageView) {
_backgroundImageView = [[UIImageView alloc] init];
_backgroundImageView.image = [UIImage imageNamed:@"mine_gift_bg"];
}
return _backgroundImageView;
}
- (NetImageView *)imageView {
if (!_imageView) {
NetImageConfig * config = [[NetImageConfig alloc]init];
config.imageType = ImageTypeUserIcon;
config.placeHolder = [UIImageConstant defaultAvatarPlaceholder];
_imageView = [[NetImageView alloc] initWithConfig:config];
_imageView.layer.masksToBounds = YES;
}
return _imageView;
}
- (UILabel *)titleLabel {
if (!_titleLabel) {
_titleLabel = [UILabel labelInitWithText:@""
font:[UIFont systemFontOfSize:11 weight:UIFontWeightMedium]
textColor:UIColorFromRGB(0x515860)];
}
return _titleLabel;
}
- (UILabel *)countLabel {
if (!_countLabel) {
_countLabel = [UILabel labelInitWithText:@""
font:[UIFont systemFontOfSize:11 weight:UIFontWeightRegular]
textColor:UIColorFromRGB(0x515860)];
_countLabel.alpha = 0.6f;
}
return _countLabel;
}
@end
@interface XPMineGiftsTableViewCell()<UICollectionViewDelegateFlowLayout, UICollectionViewDataSource>
@property (nonatomic, strong) UICollectionView *giftsCollectionView;
@property (nonatomic, strong) UILabel *noDataLabel;
@end
@implementation XPMineGiftsTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
self.contentView.backgroundColor = [UIColor whiteColor];
[self.contentView addSubview:self.giftsCollectionView];
[self.giftsCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.contentView).offset(14);
make.edges.mas_equalTo(self.contentView);
}];
[self.contentView addSubview:self.noDataLabel];
[self.noDataLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.mas_equalTo(self.contentView);
}];
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
}
- (void)setGiftsDataSource:(NSArray *)giftsDataSource {
_giftsDataSource = giftsDataSource;
self.noDataLabel.hidden = giftsDataSource.count > 0;
[self.giftsCollectionView reloadData];
}
#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return self.giftsDataSource.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
XPMineGiftCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Gift Cell"
forIndexPath:indexPath];
UserGiftWallInfoModel *giftModel = [self.giftsDataSource xpSafeObjectAtIndex:indexPath.row];
if (giftModel) {
cell.imageView.imageUrl = giftModel.picUrl;
cell.titleLabel.text = giftModel.giftName;
cell.countLabel.text = [NSString stringWithFormat:@"x%ld", (long)giftModel.reciveCount];
}
return cell;
}
#pragma mark - UICollectionViewDelegateFlowLayout
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
return CGSizeMake(86, 120);
}
#pragma mark -
- (UICollectionView *)giftsCollectionView {
if (!_giftsCollectionView) {
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.scrollDirection = UICollectionViewScrollDirectionVertical;
layout.minimumInteritemSpacing = 10;
layout.minimumLineSpacing = 10;
_giftsCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero
collectionViewLayout:layout];
_giftsCollectionView.backgroundColor = [UIColor clearColor];
_giftsCollectionView.delegate = self;
_giftsCollectionView.dataSource = self;
[_giftsCollectionView registerClass:[XPMineGiftCell class]
forCellWithReuseIdentifier:@"Gift Cell"];
}
return _giftsCollectionView;
}
- (UILabel *)noDataLabel {
if (!_noDataLabel) {
_noDataLabel = [UILabel labelInitWithText:@"暂无礼物" font:[UIFont systemFontOfSize:14 weight:UIFontWeightMedium] textColor:UIColorFromRGB(0x191919)];
_noDataLabel.textAlignment = NSTextAlignmentCenter;
_noDataLabel.alpha = 0.5;
_noDataLabel.hidden = YES;
}
return _noDataLabel;
}
@end