2017-09-18 70 views
0

有沒有辦法使集合視圖中的所有項目都適合一行,而不是自動將項目放在另一行中?我試圖複製類似Instagram的故事顯示類似下面的鏈接:適合所有項目到一個集合查看行

enter image description here

然而,在我的收藏看法,我得到來自服務器的數量,並顯示在集合視圖的信息但在顯示3個項目後,它總是進入下一行。

// number of sections function 
    override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 
     return pictures.count 
    } // end of function 
+0

做一些搜索以設置集合視圖中項目的寬度。 – rmaddy

回答

0

我想你不想在集合視圖中垂直滾動。

對於集合視圖中的水平滾動,請選擇故事板中的集合視圖並將scroll direction更改爲水平。

參考下面這個圖:

enter image description here

0

您可以添加collectionViewLayout委託方法是這樣的。 CGFloat(3.0)是您想要的項目數,您必須將它從collectionView的寬度中劃分出來

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { 
    let itemWidth: CGFloat = ((collectionView.bounds.size.width)/CGFloat(3.0)) 
    return CGSize(width: itemWidth, height: collectionView.bounds.size.height) 
} 
相關問題