UICollection视图调整屏幕大小的单元大小 [英] UICollection View Adjust Cell Size for Screen Size

查看:168
本文介绍了UICollection视图调整屏幕大小的单元大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

集合视图代码只是

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

}

布局在IB中设置我想获得布局先添加更多

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

推荐答案

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

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.

这篇关于UICollection视图调整屏幕大小的单元大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆