[英]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.