Jay*_*iyk 5 uiview ios uicollectionview swift swift2
您好我想知道我们是如何实现这一目标的?
在UITableView中我们可以简单地做tableView.tableHeaderView = SomeView;或tableView.tableFooterView = SomeView;
但我想知道如何为UICollectionView做同样的事情.
PS:不是页眉和页脚
试试吧...
ViewDidLoad中的第一个注册类
registerClass(myFooterViewClass, forSupplementaryViewOfKind: UICollectionElementKindSectionFooter, withReuseIdentifier: "Footer")
Run Code Online (Sandbox Code Playgroud)
然后使用这种方法
override func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView {
switch kind {
case UICollectionElementKindSectionHeader:
let header = collectionView.dequeueReusableSupplementaryViewOfKind(kind, withReuseIdentifier: "Header", forIndexPath: indexPath) as! UICollectionReusableView
header = SomeView
return header
case UICollectionElementKindSectionFooter:
let footer = collectionView.dequeueReusableSupplementaryViewOfKind(kind, withReuseIdentifier: "Footer", forIndexPath: indexPath) as! UICollectionReusableView
footer= SomeView
return footer
default:
print("anything")
}
}
Run Code Online (Sandbox Code Playgroud)
我希望它有所帮助......
UITableView具有全局标头tableHeaderView和tableFooterView,但UICollectionView没有全局标头,因此您必须使用节标头。
| 归档时间: |
|
| 查看次数: |
10113 次 |
| 最近记录: |