CNLiveCycleView.m 2.3 KB
//
//  CNLiveCycleView.m
//  CNLiveCServiceModule
//
//  Created by CNLive on 2021/11/27.
//

#import "CNLiveCycleView.h"
#import "CNLiveCycleCell.h"


@interface CNLiveCycleView()<UICollectionViewDataSource>
@property (nonatomic, strong) UICollectionView *collectionView;
@end
static NSString *CNCycleCellID   =  @"CNCycleCellID";
@implementation CNLiveCycleView
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = kClearColor;
        self.collectionView.dataSource = self;
        [self makeSubViewsLayout];
    }
    return self;
}

-(void)makeSubViewsLayout
{
    self.collectionView.frame = CGRectMake(0, 0, self.width, self.height - 20);
}
#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{

    return self.dataSource.count;
}

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    CNLiveCycleCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CNCycleCellID forIndexPath:indexPath];
    CNLiveSearchHotsModel *model = self.dataSource[indexPath.row];
    cell.model = model;
    return cell;
}
#pragma mark - Setting&&Getting
- (void)setModel:(CNLiveSearchHotsModel *)model
{
    _model = model;
    self.dataSource = model.lists;
    if ([model.title isEqualToString:@"中国媒体号"]||[model.title isEqualToString:@"中国网中国号"]) {
        self.collectionView.backgroundColor = CNLiveColorWithHexString(@"#F9FAFB");
        self.collectionView.layer.cornerRadius = 5.66;
    }else
    {
        self.collectionView.backgroundColor = kClearColor;
    }
}
- (void)setDataSource:(NSArray *)dataSource
{
    _dataSource = dataSource;
    [self.collectionView reloadData];
   
}
- (UICollectionView *)collectionView
{
    if (!_collectionView) {
        for (UIView *view in self.subviews) {
            if ([view isKindOfClass:[UICollectionView class]]) {
                _collectionView = (UICollectionView *)view;
                [_collectionView registerClass:[CNLiveCycleCell class] forCellWithReuseIdentifier:CNCycleCellID];
                _collectionView.backgroundColor = kClearColor;
            }
        }
    }
    return _collectionView;
}
@end