117 lines
4.4 KiB
Objective-C
117 lines
4.4 KiB
Objective-C
//
|
|
// XPHomeHotRoomTableViewCell.m
|
|
// xplan-ios
|
|
//
|
|
// Created by 冯硕 on 2022/2/21.
|
|
// 人气主播
|
|
|
|
#import "XPHomeHotRoomTableViewCell.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
///Tool
|
|
#import "XPMacro.h"
|
|
#import "ThemeColor.h"
|
|
#import "UIImage+Utils.h"
|
|
///View
|
|
#import "XPHomeHotRoomCollectionViewCell.h"
|
|
|
|
@interface XPHomeHotRoomTableViewCell ()<UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
|
|
///列表
|
|
@property (nonatomic,strong) UICollectionView *collectionView;
|
|
@property (nonatomic, strong) UIImageView *bgImageView;
|
|
|
|
@end
|
|
|
|
@implementation XPHomeHotRoomTableViewCell
|
|
|
|
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
|
|
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
|
|
[self initSubViews];
|
|
[self initSubViewConstraints];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
#pragma mark - Private Method
|
|
- (void)initSubViews {
|
|
self.backgroundColor = [UIColor clearColor];
|
|
self.selectionStyle = UITableViewCellSelectionStyleNone;
|
|
[self.contentView addSubview:self.bgImageView];
|
|
[self.contentView addSubview:self.collectionView];
|
|
}
|
|
|
|
- (void)initSubViewConstraints {
|
|
[self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.right.mas_equalTo(self.contentView).inset(15 * kScreenScale);
|
|
make.top.bottom.mas_equalTo(self.contentView);
|
|
}];
|
|
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.right.mas_equalTo(self.contentView).inset(15 * kScreenScale);
|
|
make.top.bottom.mas_equalTo(self.contentView);
|
|
}];
|
|
}
|
|
|
|
#pragma mark - UICollectionViewDelegate And UICollectionViewDatasource
|
|
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
return CGSizeMake(74 * kScreenScale, 117 * kScreenScale);
|
|
}
|
|
|
|
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
|
|
return self.hotAnchorList.count;
|
|
}
|
|
|
|
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
XPHomeHotRoomCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([XPHomeHotRoomCollectionViewCell class]) forIndexPath:indexPath];
|
|
HomeRecommendRoomModel * info = [self.hotAnchorList objectAtIndex:indexPath.row];
|
|
cell.hotRoomInfo = info;
|
|
cell.indexPathRow = indexPath.row;
|
|
return cell;
|
|
}
|
|
|
|
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
[collectionView deselectItemAtIndexPath:indexPath animated:YES];
|
|
if (self.hotAnchorList.count > 0) {
|
|
HomeRecommendRoomModel * info = [self.hotAnchorList objectAtIndex:indexPath.row];
|
|
if (self.delegate && [self.delegate respondsToSelector:@selector(xPHomeHotRoomTableViewCell:didClickItem:)]) {
|
|
[self.delegate xPHomeHotRoomTableViewCell:self didClickItem:info];
|
|
}
|
|
}
|
|
}
|
|
|
|
#pragma mark - Getters And Setters
|
|
- (void)setHotAnchorList:(NSArray *)hotAnchorList {
|
|
_hotAnchorList = hotAnchorList;
|
|
[self.collectionView reloadData];
|
|
}
|
|
|
|
- (UICollectionView *)collectionView{
|
|
if (!_collectionView) {
|
|
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
|
|
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
|
|
layout.minimumLineSpacing = 10 * kScreenScale;
|
|
layout.minimumInteritemSpacing = 0;
|
|
layout.sectionInset = UIEdgeInsetsMake(0, 12, 0, 12);
|
|
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
|
|
_collectionView.dataSource = self;
|
|
_collectionView.tag = 1001;
|
|
_collectionView.delegate = self;
|
|
_collectionView.backgroundColor = [UIColor clearColor];
|
|
_collectionView.showsHorizontalScrollIndicator = NO;
|
|
[_collectionView registerClass:[XPHomeHotRoomCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([XPHomeHotRoomCollectionViewCell class])];
|
|
}
|
|
return _collectionView;
|
|
}
|
|
|
|
- (UIImageView *)bgImageView {
|
|
if (!_bgImageView) {
|
|
UIImageView *imageView = [[UIImageView alloc] init];
|
|
imageView.image = [UIImage gradientColorImageFromColors:@[UIColorFromRGB(0xEAFFFA),UIColorFromRGB(0xF7FBF0)] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(KScreenWidth - 15*2*kScreenScale, 155 * kScreenScale)];
|
|
imageView.layer.cornerRadius = 12;
|
|
imageView.layer.masksToBounds = YES;
|
|
_bgImageView = imageView;
|
|
}
|
|
return _bgImageView;
|
|
}
|
|
|
|
@end
|