【发布时间】:2015-01-28 21:05:22
【问题描述】:
我正在尝试创建分组图像的 UICollectionView(当前使用来自互联网的随机图像),每个组都有自己的标题。
我的问题是 - 我无法正确显示标题视图。
我将标题视图的背景颜色设置为黄色。
这是标题视图:
以下是包含两个组及其各自标题的当前集合:
如您所见,标题已调整为其成员单元格的大小并定位在集合中,而不是位于其预期的标题位置。
这是布局代码:
override func viewDidLoad() {
createFriends(sender:self)
let layout = UICollectionViewFlowLayout()
layout.scrollDirection = .Vertical;
layout.itemSize = CGSizeMake(50.0, 50.0);
layout.sectionInset = UIEdgeInsetsMake(10.0, 10.0, 50.0, 10.0);
layout.headerReferenceSize = CGSizeMake(320.0, 40.0)
layout.minimumLineSpacing = 10.0;
layout.minimumInteritemSpacing = 10.0;
gCollectionView.collectionViewLayout = layout
let myNib = UINib(nibName: "(1.1)HeaderViewCell",bundle: nil)
gCollectionView.registerNib(myNib, forCellWithReuseIdentifier: kCellIdentifier)
}
这是标题代码(可能不需要参考尺寸,因为它是在布局中设置的):
func collectionView(collectionView: UICollectionView, layout
collectionViewLayout: UICollectionViewLayout,
referenceSizeForHeaderInSection section: Int) -> CGSize {
return CGSizeMake(100.0, 30.0)
}
func collectionView(collectionView: UICollectionView,
viewForSupplementaryElementOfKind kind: String,
atIndexPath indexPath: NSIndexPath) ->
UICollectionReusableView {
let headerView =
collectionView.dequeueReusableCellWithReuseIdentifier(kCellIdentifier,
forIndexPath: indexPath) as mediaHeaderView
headerView.backgroundColor = UIColor.yellowColor() // ... YELLOW background
return headerView
}
问题:为什么我没有为每组项目获得正确定位的标题?
【问题讨论】:
-
那些图片虽然是O_o