UICollection视图调整屏幕大小的单元格大小

时间:2022-11-11 11:48:00

Currently i have a collection view which takes up most of my screen at the 3.5 inch screen size.The collection view is 51 pixels from the top and 20 pixels from the bottom of the screen. I am using the cells with UIPageControl to create a paged layout, with one cell per page. When switching to the 4 inch size, using constraints i can get the collection view to expand into the new space (maintaining the 51 pixels from the top and 20 from bottom), but the cell size stays the same, so now there is a bunch of empty space at the top and bottom of the cell. I tried using constraints, but it appears you can't set them for cells. How do i expand the cell size bigger to fill the empty space on the iPhone 5?

目前我有一个收集视图占据了我3.5英寸屏幕尺寸的大部分屏幕。收集视图从顶部开始是51像素,从屏幕底部开始是20像素。我使用UIPageControl的单元格来创建分页布局,每页一个单元格。当切换到4英寸大小时,使用约束我可以让集合视图扩展到新空间(保持从顶部51个像素和从底部20个),但单元格大小保持不变,所以现在有一堆细胞顶部和底部的空白空间。我尝试使用约束,但看起来你不能为细胞设置它们。如何扩大单元格大小以填充iPhone 5上的空白区域?

The collection view code is just

集合视图代码就是

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
              cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
MyCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
return cell;

}

The layout is setup in IB I want to get the layout working first before I add more

布局是在IB中设置的我想在添加更多内容之前先让布局工作

UICollection视图调整屏幕大小的单元格大小

UICollection视图调整屏幕大小的单元格大小

2 个解决方案

#1


71  

You can either use the UICollectionViewFlowLayout method itemSize property to set the UICollectionViewCell size, or use the delegate method, collectionView:layout:sizeForItemAtIndexPath: if you need to dynamically set the sizes of the UICollectionViewCells.

您可以使用UICollectionViewFlowLayout方法itemSize属性来设置UICollectionViewCell大小,也可以使用委托方法collectionView:layout:sizeForItemAtIndexPath:如果需要动态设置UICollectionViewCells的大小。

#2


7  

CollectionView layout Delegate that will help you to resize your Cell as you need.
- (CGSize)collectionView:(UICollectionView *)collectionView 
                          layout:(UICollectionViewLayout*)collectionViewLayout 
          sizeForItemAtIndexPath:(NSIndexPath *)indexPath;

#1


71  

You can either use the UICollectionViewFlowLayout method itemSize property to set the UICollectionViewCell size, or use the delegate method, collectionView:layout:sizeForItemAtIndexPath: if you need to dynamically set the sizes of the UICollectionViewCells.

您可以使用UICollectionViewFlowLayout方法itemSize属性来设置UICollectionViewCell大小,也可以使用委托方法collectionView:layout:sizeForItemAtIndexPath:如果需要动态设置UICollectionViewCells的大小。

#2


7  

CollectionView layout Delegate that will help you to resize your Cell as you need.
- (CGSize)collectionView:(UICollectionView *)collectionView 
                          layout:(UICollectionViewLayout*)collectionViewLayout 
          sizeForItemAtIndexPath:(NSIndexPath *)indexPath;