CNLiveCycleView.m
2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//
// 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