1
ヘッダーにラベルを挿入しようとしましたが、collectionViewをスクロールすると別のラベルがビューに追加されます。どうやってこれをやめることができますか? enter image description hereCollectionViewヘッダーのラベルの問題
override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "header", for: indexPath)
header.backgroundColor = .white
let label = UILabel(frame: header.bounds)
label.text = colorsArray[indexPath.section]
header.addSubview(label)
return header
}
私は本当にヘッダーを使用する必要があるので、私はそれを行うことはできません。 –
しかし、あなたはUICollectionReusableViewでヘッダをサブクラス化することができます – Retterdesdialogs
ああ、申し訳ありません、コード 'cell.label.text = "something"'は私を混乱させました。 あなたは正しいです、それは非常にうまくいきます。ありがとう –