如何解决标题中的不同标签取决于集合视图中的部分
let titles = ["Popularity","Top Rated","Release Date","Revenue"]
func collectionView(_ collectionView: UICollectionView,viewForSupplementaryElementOfKind kind: String,at indexPath: IndexPath) -> UICollectionReusableView {
let header = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionHeader,withReuseIdentifier: Header.identifier,for: indexPath) as! Header
header.label.text = titles[indexPath.section]
return header
}
我想要做的标题的文本会根据每个部分的标题数组而有所不同。我可以看到标题中的空白,但其中没有标题。
这是我的 Header 类:
class Header: UICollectionReusableView {
static let identifier = "Header"
let label = UILabel()
override init(frame: CGRect) {
super.init(frame: frame)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func layoutSubviews() {
super.layoutSubviews()
label.frame = bounds
}
}
也在 viewDidLoad() 中,我写了这个。
collectionV.register(Header.self,forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader,withReuseIdentifier: Header.identifier)
我错过了什么?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。