簡體   English   中英

集合視圖單元格之間的空間始終為0

[英]Space between collection view cells is always 0

我試圖在單元格之間留一個空間,但是由於某種原因,它始終為0。我在做什么錯?

import UIKit

class AlbumPlayerProgressBar: UICollectionView {

    ...

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        self.register(UINib(nibName: "ProgressBarCell", bundle: nil), forCellWithReuseIdentifier: NSStringFromClass(ProgressBarCell.self))
        self.dataSource = self
        self.delegate = self
    }
}

extension AlbumPlayerProgressBar: UICollectionViewDataSource
{
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return numOfSlides
    }

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: NSStringFromClass(ProgressBarCell.self), for: indexPath) as! ProgressBarCell

        ...
        return cell
    }
}

extension AlbumPlayerProgressBar: UICollectionViewDelegateFlowLayout
{
    func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, sizeForItemAt: IndexPath) -> CGSize
    {       
        return CGSize(width: segmentWidth, height: segmentHeight)
    }

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat
    {
        return 100
    }
}

您可以使用minimumInteritemSpacingForSectionAtminimumLineSpacingForSectionAt ,並將返回值設置為所需的空間:

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
    return 1.0
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
    return 1.0
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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