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
我要把单元格移到左上角
最佳答案
如果不是布局约束问题,则:
collectionView.contentInset = UIEdgeInsets.zero
也有可能您已经实现了:
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
//...
}
在这种情况下,您需要将methods return value
top
属性设置为0
关于ios - Swift iOS如何删除顶部填充UICollectionView,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52946131/