我有一個應用程序,其中包含一個視圖控制器中的文本字段和另一個視圖控制器中的集合視圖。我正在顯示在集合視圖單元格中鍵入的文本。這工作很好,但是我硬編碼了兩個單元格,我想在用戶輸入的文本上面顯示。我想改變這兩個單元格的背景,這可能嗎? 「名稱」和「成績」是硬編碼的項目由於任何幫助如何更改UICollectionview單元格上的背景swift
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return ScoreArray.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let Cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath)
let Mycell = Cell.viewWithTag(1) as! UILabel
Mycell.text = ScoreArray[indexPath.row]
return Cell
}
override func viewDidLoad() {
super.viewDidLoad()
ScoreArray.append("NAMES")
ScoreArray.append("SCORES")
}
是什麼增加的UIView()爲子視圖嗎?這似乎令人費解。 –
你的問題對我來說很困惑什麼是改變背景的意思..改變顏色,查看或顯示任何東西? – amber