首页 > 其他 > 详细

collection view 根据delegate来布局cell的大小

时间:2015-03-26 10:51:37      阅读:188      评论:0      收藏:0      [点我收藏+]
一般我们在做collection view时都是用 UICollectionViewFlowLayout来进行布局.使用UICollectionViewDelegate作为代理.但是这样每个cell的大小是我们不方便通过代码动态确定的.在做项目是发现源码里有  

@protocol UICollectionViewDelegateFlowLayout <UICollectionViewDelegate>

@optional

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath;

...

@end


于是把collection view 的delegate 由 <UICollectionViewDelegate>换成<UICollectionViewDelegateFlowLayout>并实现

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
return CGSizeMake(width, height);
}
这样就可以实现根据不同的indexpath确定cell的大小.

collection view 根据delegate来布局cell的大小

原文:http://blog.csdn.net/zhangping871/article/details/44645983

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!