2017-06-12 85 views
1

目前我使用SWIFT 3和故事板,一派一切,看着所有的StackOverflow類似的問題,什麼也沒得到那麼遠。如何在Swift 3中設置collectionview單元格的間距?

在我的例子,項目,

我Collection視圖看起來像這樣 Simulator Screenshot

這不是我想要的,我想沒有間隔的網格佈局可言,我編輯的故事板值ddin'牛逼有什麼東西在那裏,所以對於我用這個代碼

let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout() 
let width = UIScreen.main.bounds.width 
layout.sectionInset = UIEdgeInsets(top: 0, left: 5, bottom: 0, right: 5) 
layout.itemSize = CGSize(width: width/2, height: width/2) 
layout.minimumInteritemSpacing = 0 
layout.minimumLineSpacing = 0 
collectionView!.collectionViewLayout = layout 

沒有工作,要麼:(

+0

https://stackoverflow.com/a/38028456/1630618 – vacawama

回答

2
'if let layout = self.collectionView.collectionViewLayout as? UICollectionViewFlowLayout{ 
      let width = UIScreen.main.bounds.width 
      layout.sectionInset = UIEdgeInsets(top: 0, left: 5, bottom: 0, right: 5) 
      layout.itemSize = CGSize(width: width/2, height: width/2) 
      layout.minimumInteritemSpacing = 0 
      layout.minimumLineSpacing = 0 
     }' 
相關問題