常用方法
添加协议 <UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
#pragma mark - 懒加载
- (UICollectionView *)collectionView {
if (_collectionView == nil) {
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.scrollDirection = UICollectionViewScrollDirectionVertical;
layout.itemSize = CGSizeMake(Main_Screen_Width * 0.5 , 190 * kScreenHeightRatio);
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, Navi_Height + 50, Main_Screen_Width , Main_Screen_Height - Navi_Height - 50) collectionViewLayout:layout];
_collectionView.backgroundColor = [UIColor colorWithHexString:@"#F6F7F8"];
_collectionView.dataSource = self;
_collectionView.delegate = self;
_collectionView.pagingEnabled = NO;
_collectionView.scrollsToTop = NO;
_collectionView.showsHorizontalScrollIndicator = NO;
layout.minimumLineSpacing = 0;
layout.minimumInteritemSpacing = 0;
_collectionView.contentOffset = CGPointMake(0, 0);
[_collectionView registerClass:[UKListenStudentCollectionViewCell class] forCellWithReuseIdentifier:@"UKListenStudentCollectionViewCell"];
//注册头视图
[_collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"headview"];
}
return _collectionView;
}
#pragma mark UICollectionView
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
UKStudentListenWorkListModel *model = self.dataM[section];
return 10;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UKListenStudentCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"UKListenStudentCollectionViewCell" forIndexPath:indexPath];
return cell;
}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
if (self.data.count) {
UICollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"headview" forIndexPath:indexPath];
return headerView;
}
return nil;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
return 0;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
return 0;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
return CGSizeMake(Main_Screen_Width, 44);
}
- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
}
- (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
}
网友评论