admin
2023-04-21 0b3a4aaf99ea251bc8e27b96115288f0988fcffe
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//
//  HotLiveTableViewCell.m
//  BuWanVideo2.0
//
//  Created by apple on 2017/5/31.
//  Copyright © 2017年 com.yeshi.buwansheque.ios. All rights reserved.
//
 
#import "HotLiveTableViewCell.h"
#import "HotLiveCollectionViewCell.h"
 
@implementation HotLiveTableViewCell
 
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    _Hotlive.delegate=self;
    _Hotlive.dataSource=self;
    
    UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc] init];
    //指定布局方式为垂直
    flow.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    flow.minimumLineSpacing = 10;//最小行间距(当垂直布局时是行间距,当水平布局时可以理解为列间距)
    flow.minimumInteritemSpacing = 0;//两个单元格之间的最小间距
    
    [_Hotlive setCollectionViewLayout:flow];
    
    //注册瀑布流的cell
    [_Hotlive registerNib:[UINib nibWithNibName:@"HotLiveCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"HotLiveCollectionViewCell"];
    
    //隐藏滚动条
    _Hotlive.showsVerticalScrollIndicator=NO;
    _Hotlive.showsHorizontalScrollIndicator=NO;
    
    //设置背景色为透明
    self.backgroundColor=[UIColor clearColor];
    _Hotlive.backgroundColor=[UIColor clearColor];
}
 
-(void)setCellData:(NSMutableArray *)cellData{
    _cellData=cellData;
    [_Hotlive reloadData];
}
 
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
 
    // Configure the view for the selected state
}
 
#pragma mark -UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.cellData.count;
}
 
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary *tempDic=_cellData[indexPath.row];
    
    HotLiveCollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"HotLiveCollectionViewCell" forIndexPath:indexPath];
    NSString *PicStr=[tempDic objectForKey:@"HeadPic"];
    PicStr=[PicStr stringByReplacingOccurrencesOfString:@"100_100"withString:@"200_200"];
    [cell.headPic setYthImageWithURL:PicStr placeholderImage:[UIImage imageNamed:@"默认加载图片"]];
    [cell.roomPic setYthImageWithURL:[tempDic objectForKey:@"RoomPic"] placeholderImage:[UIImage imageNamed:@"默认加载图片"]];
    cell.roomPic.layer.cornerRadius=15;
    cell.roomPic.layer.masksToBounds=YES;
    cell.name.text=[tempDic objectForKey:@"Name"];
    cell.liveNum.text=[NSString stringWithFormat:@"%@人在看",[tempDic objectForKey:@"LiveNum"]];
    
    return cell;
}
 
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}
 
#pragma mark -UICollectionViewDelegate
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    NSIndexPath *index=[NSIndexPath indexPathForRow:indexPath.row inSection:_tableViewindex.section];
    self.clickIndexpath(index);
}
 
#pragma mark -UICollectionViewDelegateFlowLayout
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    return CGSizeMake(120, 160);
}
 
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    return UIEdgeInsetsMake(0, 10, 0, 10);//分别为上、左、下、右
}
 
@end