我想使用UICollectionView,可以创建以下布局:
如您所见,有两种不同大小的单元格.一个是行的1/4,另一个是3/4.是否可以使用UICollectionView创建这种布局?
谁会教我怎么做?还是有样品??? 我已经学过很多教程和参考资料.但还是不知道怎么做..
谢谢!
好吧,我暂时硬编码了项目宽度(72.0和23.0).5.0的其余部分将用于临时间距和edgeInsets.此代码将为您提供您想要的内容.
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section { return 10.0; } - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section { return 10.0; } #pragma mark - CollectionViewFlowLayout Methods - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { CGSize newSize = CGSizeZero; newSize.height = 100; CGRect screenBounds = [[UIScreen mainScreen] bounds]; CGSize screenSize = screenBounds.size; if(indexPath.item % 4 == 0 || indexPath.item % 4 == 3) { // Size : 1/4th of screen newSize.width = screenSize.width * 0.23; } else { // Size : 3/4th of screen newSize.width = screenSize.width * 0.72; } return newSize; } - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section { return UIEdgeInsetsMake(10, 2.0, 10, 2.0); }