簡體   English   中英

UICollection視圖調整屏幕大小的單元格大小

[英]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中設置我希望在添加更多之前首先使布局工作

iPhone 5查看。我想填補空白空間

iPhone 4查看

您可以使用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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM