[英]How to change a UICollection View cell size form IBAction in cell object
[英]UICollection View Adjust Cell Size for Screen Size
目前我的收藏视图占据了我3.5英寸屏幕尺寸的大部分屏幕。收集视图从顶部开始是51像素,从屏幕底部开始是20像素。 我使用UIPageControl
的单元UIPageControl
来创建分页布局,每页一个单元格。 当切换到4英寸大小时,使用约束我可以使集合视图扩展到新空间(保持从顶部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:
如果需要动态设置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.