Files
yinmeng-ios/xplan-ios/Main/Home/View/Cell/XPHomeHotRoomTableViewCell.m
2022-03-07 19:33:16 +08:00

96 lines
3.5 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"
///View
#import "XPHomeHotRoomCollectionViewCell.h"
@interface XPHomeHotRoomTableViewCell ()<UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
///列表
@property (nonatomic,strong) UICollectionView *collectionView;
@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.collectionView];
}
- (void)initSubViewConstraints {
[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(148 * kScreenScale, 155 * 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;
_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;
}
@end