[英]Header in CollectionView not Displaying iOS Swift
I want to add a few buttons to the header of a Collection view. 我想在“集合”视图的标题中添加一些按钮。 Enabled 'Section Header' from the storyboard.
从情节提要中启用“部分标题”。 Then dragged a 'view' to that header.
然后将“视图”拖动到该标题。 And put its background color to green
并将其背景色设为绿色
But I don't why it's not displaying. 但是我不为什么它没有显示。 In the simulator as you see, only a blank space for the header.
如您所见,在模拟器中,标题只有一个空格。
Use this Method 使用这个方法
Give name in CollectionHeaderCell
在
CollectionHeaderCell
命名
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
switch kind {
case UICollectionElementKindSectionHeader:
let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "Header", for: indexPath as IndexPath)
headerView.backgroundColor = UIColor.blue;
return headerView
case UICollectionElementKindSectionFooter:
let footerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "Footer", for: indexPath as IndexPath)
footerView.backgroundColor = UIColor.green;
return footerView
default:
assert(false, "Unexpected element kind")
}
}
// make a cell for each cell index path //为每个单元格索引路径创建一个单元格
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("InviteFriendCell", forIndexPath: indexPath)
let profileimage: UIImageView = (cell.viewWithTag(5) as! UIImageView)
profileimage.image = UIImage(named:arrayofdata[indexPath.row]["image"]!)
return cell
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.