下面以创建footerview为例:
1、在UICollectionViewFlowLayout中添加:
flowLayout.footerReferenceSize =CGSizeMake(ScreenWidth, 30);
2、创建自定义的Footerview,继承于UICollectionReusableView ,这里命名为:"MyFooterView"
3、注册这个类
[_collectionViewregisterClass:[MyFooterViewclass]forSupplementaryViewOfKind:UICollectionElementKindSectionFooterwithReuseIdentifier:@"footer"];
4、添加方法
-(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
if ([kindisEqualToString:UICollectionElementKindSectionFooter]) {
MyFooterView *footerView = [collectionViewdequeueReusableSupplementaryViewOfKind:kindwithReuseIdentifier:@"footer"forIndexPath:indexPath];
return footerView;
}
returnnil;
}