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
backgorund黑色为UICollectionViewCell
我想将Cell移到左上方
答案 0 :(得分:1)
如果不是布局约束问题,则:
collectionView.contentInset = UIEdgeInsets.zero
也可能已实现:
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
//...
}
在这种情况下,您需要将方法的返回值top
属性设置为0
答案 1 :(得分:0)
尝试在UIViewController
中设置viewDidLoad
的这两个属性
extendedLayoutIncludesOpaqueBars = true
automaticallyAdjustsScrollViewInsets = false
请检查情节提要中的标题大小,尝试将其设置为零。
答案 2 :(得分:0)