簡體   English   中英

CollectionView部分中的標題

[英]Title in section CollectionView

我有一個CollectionView,並希望將標題放在各節中,

如何將標題放置在CollectionView中?

謝謝

您必須創建其標題視圖

- (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/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM