首先,你在XIB 上,选中
collectionView 然后将headView或者footerView 勾上, 注意: 你如果没有footerView 就不要勾了,因为不实现的话会报错,headerView 同里
然后在XIB 或者storyboard上面 制作出你想要的效果,
最后,你需要在代码里面实现一个协议,这样 headView 和 footerView就可以显示出来了,如果不实现协议, headView 和 footerView 显示不出来
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
UICollectionReusableView *reusableview = nil;
if (kind == UICollectionElementKindSectionHeader){
UICollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"header" forIndexPath:indexPath];
reusableview = headerView;
}
if (kind == UICollectionElementKindSectionFooter){
UICollectionReusableView *footerview = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"footer" forIndexPath:indexPath];
reusableview = footerview;
}
return reusableview;
}
over,这样就显示出来了..
在你设置UICollectionView的透明度的时候, 它上面的单元格等等,都会透明度也会改变