1

2 つのセクションを含むがあり、uicollectionview各セクションに異なるサイズのフッターを追加したいと考えています。見た IB から、コレクションごとに 1 つのフッターとヘッダーしか追加できません。

2つの異なるフッターを登録する場合、コードで可能ですか? または、各セクションの実行時にフッターのサイズを変更することはできますか?

4

1 に答える 1

7

はい..可能です..2つのオプションがあります

オプション 1 : 異なるフッター ビューを登録する

さまざまな再利用識別子を使用して、コードからフッター ビューを登録する

    registerClass:forSupplementaryViewOfKind:withReuseIdentifier:     

それで

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
   {
NSString *identifier = nil;
if ([kind isEqualToString:UICollectionElementKindSectionFooter]) {
    if (indexPath.section == 0) {
        identifier = @"footerViewOne";
    }
    else{
        identifier = @"footerViewTwo";
    }

}
UICollectionReusableView *supplementaryView = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:identifier forIndexPath:indexPath];


return supplementaryView;
}  

オプション 2 : フッター ビューのサイズを変更するだけ

そのためには、UICollectionViewDelegateFlowLayoutメソッド を使用します

 - (CGSize)collectionView:(PSUICollectionView *)collectionView layout:(PSUICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section
{
   if (section==0) {
    return  CGSizeMake(500, 50);
  }
  else
  {
    return CGSizeMake(200, 50);
  }
} 
于 2013-04-08T11:52:35.303 に答える