Boa*_*ssi 1 footer uicollectionview
我有一个uicollectionview包含2个部分,我想为每个部分添加一个不同大小的页脚.从IB我看到我每个集合只能添加一个页脚和标题.
如果我会注册2个不同的页脚,是否可能通过代码?或者可以在每个部分的运行时间中更改页脚的大小?
是..有可能..你有两个选择
选项1:注册不同的页脚视图
通过使用不同的重用标识符来注册页脚视图
registerClass:forSupplementaryViewOfKind:withReuseIdentifier:
Run Code Online (Sandbox Code Playgroud)
然后
- (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;
}
Run Code Online (Sandbox Code Playgroud)
选项2:只需更改页脚视图的大小
为此使用UICollectionViewDelegateFlowLayout方法
- (CGSize)collectionView:(PSUICollectionView *)collectionView layout:(PSUICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section
{
if (section==0) {
return CGSizeMake(500, 50);
}
else
{
return CGSizeMake(200, 50);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1924 次 |
| 最近记录: |