CollectionView部分中的标题

时间:2018-09-26 11:58:59

标签: ios uicollectionview

我有一个CollectionView,并希望将标题放在各个部分中,

如何在CollectionView中放置标题?

谢谢

1 个答案:

答案 0 :(得分:0)

您必须创建其标题视图

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPathUICollectionReusableView *reusableview = nil;

if (kind == UICollectionElementKindSectionHeader) {
    RecipeCollectionHeaderView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderView" forIndexPath:indexPath];
    NSString *title = [[NSString alloc]initWithFormat:@"Recipe Group #%i", indexPath.section + 1];
    headerView.title.text = title;
    UIImage *headerImage = [UIImage imageNamed:@"header_banner.png"];
    headerView.backgroundImage.image = headerImage;

    reusableview = headerView;
}

if (kind == UICollectionElementKindSectionFooter) {
    UICollectionReusableView *footerview = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"FooterView" forIndexPath:indexPath];

    reusableview = footerview;}
    return reusableview;}

选中此项以获取完整信息。 https://www.appcoda.com/supplementary-view-uicollectionview-flow-layout/

相关问题