UICollection View调整屏幕大小的单元大小
目前我有一个采集视图占用我的大部分屏幕在3.5英寸的屏幕大小。集合视图是从顶部51像素,从屏幕的底部20像素。 我正在使用UIPageControl
的单元UIPageControl
来创build分页布局,每页一个单元格。 当切换到4英寸的大小,使用约束我可以得到collections视图扩大到新的空间(保持51像素从顶部和20从底部),但单元格大小保持不变,所以现在有一堆在单元格顶部和底部的空白空间。 我尝试使用约束,但似乎你不能为单元格设置它们。 如何扩大单元尺寸以填充iPhone 5上的空白空间?
集合视图代码是刚刚
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { MyCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath]; return cell; }
布局在IB中设置我想在添加更多内容之前先让布局工作
您可以使用UICollectionViewFlowLayout
方法的itemSize
属性来设置UICollectionViewCell
大小,或者使用delegate
方法collectionView:layout:sizeForItemAtIndexPath:
如果您需要dynamic设置UICollectionViewCells
的大小。
CollectionView layout Delegate that will help you to resize your Cell as you need.
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath;