代码之家  ›  专栏  ›  技术社区  ›  Adam

Swift iOS如何删除顶部填充UICollectionView

  •  0
  • Adam  · 技术社区  · 6 年前
    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

    enter image description here

    我要把单元格移到左上角

    enter image description here enter image description here

    3 回复  |  直到 6 年前
        1
  •  1
  •   fewlinesofcode user10694837    6 年前

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

    collectionView.contentInset = UIEdgeInsets.zero
    

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
            //...
        }
    

    在这种情况下,您需要设置方法返回值 top 属性到 0

        2
  •  0
  •   Ratul Sharker    6 年前

    尝试设置这两个属性 UIViewController viewDidLoad

    extendedLayoutIncludesOpaqueBars = true
    automaticallyAdjustsScrollViewInsets = false
    

    请检查情节提要中的标题大小,尝试将其设置为零。

        3
  •  0
  •   Gulfam Khan    6 年前

    我认为这是问题集的值 Y component

    Problem is here