2015-08-31 46 views
1

所以,我有問題是,集合視圖,這取決於我在用模擬器它顯示在任一個設置3(iPhone 5)列或者在另一個4列(iPhone 6)。無論屏幕有多大或多小,我都希望採集視圖始終顯示4列。以下是我目前使用的一些代碼:迅速集合視圖縮放問題

override func viewDidLoad() { 
    super.viewDidLoad() 

    let screenWidth = UIScreen.mainScreen().bounds.size.width 
    let screenHeight = UIScreen.mainScreen().bounds.size.height 


    let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout() 
    layout.sectionInset = UIEdgeInsets(top: 20, left: 10, bottom: 10, right: 10) 
    layout.itemSize = CGSize(width: 100, height: 80) 

      collview1 = UICollectionView(frame: CGRectMake(0, 0, screenWidth, screenHeight), collectionViewLayout: layout) 


    [collview1.reloadData]; 


} 

回答

1

您需要將layout.itemSize更改爲計算值。

喜歡的東西:

layout.itemSize = CGSize(width: (screenWidth - spacing)/numberOfColumns, height: desiredHeight) 

間距將連續加左,右插圖總項目間的間距。

DesiredHeight可能應該是一個計算值,以保持設備之間的你的細胞的縱橫比。

希望這會有幫助。