Ich versuche, den Hintergrund der ersten beiden Zellen in meiner Sammlung Ansicht zu ändern habe ich diesen Code versuchtrasche
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let width = self.view.frame.width
let height = self.view.frame.height
return CGSize(width: width/2.2 , height: height/6)
}
override func didRotate(from fromInterfaceOrientation: UIInterfaceOrientation) {
MyCollectionView.reloadData()
}
@IBAction func Back(_ sender: Any) {
performSegue(withIdentifier: "fourtothree", sender: nil)
}
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) as! CollectionViewCell
let MyCell = Cell.viewWithTag(1) as! UILabel
MyCell.text = ScoreArray[indexPath.row]
if indexPath.row == 0 {
Cell.backgroundColor = UIColor.gray
MyCell.font = UIFont.boldSystemFont(ofSize: 16.0)
}
if indexPath.row == 1 {
Cell.backgroundColor = UIColor.gray
MyCell.font = UIFont.boldSystemFont(ofSize: 16.0)
}
return Cell
}
Es ändert sich die Farbe der ersten beiden Zellen die groß ist . Wenn ich jedoch in den Querformat- oder Bildlaufmodus umschalte, ändert sich der Hintergrund verschiedener Zellen, nicht nur der ersten beiden.
Frage: Wie kann ich den Hintergrund nur der ersten zwei Zellen ändern, nicht mater, was der Benutzer tut?
danke arbeitete wie ein Charme. – c3pNoah