[英]UICollection View Adjust Cell Size for Screen Size
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. 目前我的收藏视图占据了我3.5英寸屏幕尺寸的大部分屏幕。收集视图从顶部开始是51像素,从屏幕底部开始是20像素。 I am using the cells with
UIPageControl
to create a paged layout, with one cell per page. 我使用
UIPageControl
的单元UIPageControl
来创建分页布局,每页一个单元格。 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. 当切换到4英寸大小时,使用约束我可以使集合视图扩展到新空间(保持从顶部51个像素和从底部20个),但单元格大小保持不变,所以现在有一堆细胞顶部和底部的空白空间。 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?
如何扩大单元格大小以填充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中设置我希望在添加更多之前首先使布局工作
您可以使用UICollectionViewFlowLayout
方法itemSize
属性来设置UICollectionViewCell
大小,也可以使用delegate
方法collectionView:layout:sizeForItemAtIndexPath:
如果需要动态设置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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.