iOS如何删除顶部填充UICollectionView

iOS如何删除顶部填充UICollectionView

override func viewDidLoad(){
    super.viewDidLoad()
    scrollView.collectionViewLayout = layout
    scrollView.delegate = self
    scrollView.dataSource = self
    scrollView.contentInset = .zero
    scrollView.scrollIndicatorInsets = .zero
    scrollView.isDirectionalLockEnabled = true
    scrollView.register(UINib(nibName: "RadioView", bundle: nil), forCellWithReuseIdentifier: "RadioViewController")
}
lazy var layout: UICollectionViewFlowLayout = {
    let layout = UICollectionViewFlowLayout()
    layout.minimumLineSpacing = 0
    layout.headerReferenceSize = .zero
    layout.sectionInset = .zero
    layout.scrollDirection = UICollectionViewScrollDirection.horizontal
    return layout
}()

背景色红色UICollectionView
背景色黑色UICollectionViewCell
ios - Swift iOS如何删除顶部填充UICollectionView-LMLPHP
我要把单元格移到左上角
ios - Swift iOS如何删除顶部填充UICollectionView-LMLPHP
ios - Swift iOS如何删除顶部填充UICollectionView-LMLPHP

最佳答案

如果不是布局约束问题,则:

collectionView.contentInset = UIEdgeInsets.zero

也有可能您已经实现了:
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
        //...
    }

在这种情况下,您需要将methods return valuetop属性设置为0

关于ios - Swift iOS如何删除顶部填充UICollectionView,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52946131/

10-13 04:00