CollectionView摆脱了列

时间:2016-01-25 18:00:00

标签: swift uicollectionview

我有以下布局(白色内部单元格是imageview)

enter image description here

问题是我想摆脱垂直白线,这是集合视图的背景。

我尝试以下代码,但它不起作用

class membersVC: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout {

var screenSize: CGRect!
var screenWidth: CGFloat!
var screenHeight: CGFloat!

@IBOutlet weak var collectionView: UICollectionView!

override func viewDidLoad() {
    super.viewDidLoad()

    screenSize = UIScreen.mainScreen().bounds
    screenWidth = screenSize.width
    screenHeight = screenSize.height

    let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
    layout.sectionInset = UIEdgeInsets(top: 20, left: 0, bottom: 10, right: 0)
    layout.itemSize = CGSize(width: screenWidth / 2, height: screenWidth / 2)
    layout.minimumInteritemSpacing = 5
    layout.minimumLineSpacing = 5


}

func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
    return 1
}

func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    return 6
}

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath!) ->
    UICollectionViewCell! {

        let cell = collectionView.dequeueReusableCellWithReuseIdentifier("membersCell", forIndexPath: indexPath) as! membersCell

        cell.bg.image = UIImage(named: "membersCell")

        return cell
}

}

2 个答案:

答案 0 :(得分:0)

        let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
        layout.minimumInteritemSpacing = 0
        layout.minimumLineSpacing = 0

答案 1 :(得分:0)

两种可能的解决方案:

1)根据需要将布局插图设置为左右值。这会将物品移到中心。

2)减少整个集合视图并将其置于中间。

如果屏幕边缘需要scrollindicators,则需要解决方案1)。