【发布时间】:2017-06-30 20:49:31
【问题描述】:
当我最初将 sectionHeader 添加到我的 collectionView 时,它确实看起来很正常。我在我的 collectionViewController.swift 中有这个,并且有一个标题类。
override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
let header = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionElementKindSectionHeader, withReuseIdentifier: "header", for: indexPath) as! HomeHeader
return header
}
一旦我将它添加到viewDidLoad(),标题就不再出现了。
let cellsAcross: CGFloat = 2
let spaceBetweenCells: CGFloat = 5
let dimX = ((collectionView?.bounds.width)! - (cellsAcross - 1) * spaceBetweenCells) / cellsAcross
let dimY = CGFloat(dimX/187 * 125)
let cellSize = CGSize(width: dimX , height: dimY)
let layout = UICollectionViewFlowLayout()
layout.scrollDirection = .vertical
layout.itemSize = cellSize
//layout.sectionInset = UIEdgeInsets(top: 1, left: 1, bottom: 1, right: 1)
layout.minimumLineSpacing = 5.0
layout.minimumInteritemSpacing = 5.0
collectionView?.setCollectionViewLayout(layout, animated: true)
collectionView?.reloadData()
我有这个强制它在所有屏幕尺寸上显示两行单元格。 (我仍然有一个问题,即没有调整单元格中所有内容的大小)。
我不确定为什么标题不再出现
(我使用的是 Swift 3)
【问题讨论】:
标签: ios swift uicollectionview uicollectionviewlayout