Files
yinmeng-ios/xplan-ios/Main/Home/View/Cell/XPHomeHotRoomTableViewCell.m

117 lines
4.4 KiB
Mathematica
Raw Normal View History

2022-02-21 20:06:09 +08:00
//
// XPHomeHotRoomTableViewCell.m
// xplan-ios
//
// Created by on 2022/2/21.
//
#import "XPHomeHotRoomTableViewCell.h"
///Third
#import <Masonry/Masonry.h>
///Tool
#import "XPMacro.h"
2022-09-22 14:08:26 +08:00
#import "ThemeColor.h"
#import "UIImage+Utils.h"
2022-02-21 20:06:09 +08:00
///View
#import "XPHomeHotRoomCollectionViewCell.h"
@interface XPHomeHotRoomTableViewCell ()<UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
///
@property (nonatomic,strong) UICollectionView *collectionView;
2022-09-22 14:08:26 +08:00
@property (nonatomic, strong) UIImageView *bgImageView;
2022-02-21 20:06:09 +08:00
@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;
2022-09-22 14:08:26 +08:00
[self.contentView addSubview:self.bgImageView];
2022-02-21 20:06:09 +08:00
[self.contentView addSubview:self.collectionView];
}
- (void)initSubViewConstraints {
2022-09-22 14:08:26 +08:00
[self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.mas_equalTo(self.contentView).inset(15 * kScreenScale);
make.top.bottom.mas_equalTo(self.contentView);
}];
2022-02-21 20:06:09 +08:00
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
2022-03-07 19:32:44 +08:00
make.left.right.mas_equalTo(self.contentView).inset(15 * kScreenScale);
2022-02-21 20:06:09 +08:00
make.top.bottom.mas_equalTo(self.contentView);
}];
}
#pragma mark - UICollectionViewDelegate And UICollectionViewDatasource
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
2022-09-22 14:08:26 +08:00
return CGSizeMake(74 * kScreenScale, 117 * kScreenScale);
2022-02-21 20:06:09 +08:00
}
- (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;
2022-02-25 21:18:01 +08:00
cell.indexPathRow = indexPath.row;
2022-02-21 20:06:09 +08:00
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
[collectionView deselectItemAtIndexPath:indexPath animated:YES];
2022-03-01 19:28:16 +08:00
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];
}
}
2022-02-21 20:06:09 +08:00
}
#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;
2022-03-07 19:32:44 +08:00
layout.minimumLineSpacing = 10 * kScreenScale;
2022-02-21 20:06:09 +08:00
layout.minimumInteritemSpacing = 0;
2022-09-22 14:08:26 +08:00
layout.sectionInset = UIEdgeInsetsMake(0, 12, 0, 12);
2022-02-21 20:06:09 +08:00
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
_collectionView.dataSource = self;
2022-03-07 19:32:44 +08:00
_collectionView.tag = 1001;
2022-02-21 20:06:09 +08:00
_collectionView.delegate = self;
_collectionView.backgroundColor = [UIColor clearColor];
_collectionView.showsHorizontalScrollIndicator = NO;
2022-02-21 20:06:09 +08:00
[_collectionView registerClass:[XPHomeHotRoomCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([XPHomeHotRoomCollectionViewCell class])];
}
return _collectionView;
}
2022-09-22 14:08:26 +08:00
- (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;
}
2022-02-21 20:06:09 +08:00
@end