Ich versuche, eine neue Farbe des Bildes zu setzen, während die Zelle der UICollectionView ausgewählt oder abgewählt wurde. Immer wenn ich keine Tönungsfarbe des Bildes anlege, funktioniert es, aber ich möchte nicht die Standardfarbe blue
davon haben. Also, was ich tue, ist:Farbton des Bildes möchte nicht geändert werden
In func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
Funktion, ich bin inicialazing meine Bilder mit Code:
let borderWidth = itemBorder.frame.width
let borderHeight = itemBorder.frame.height
myImage = UIImageView(frame: CGRect(x: 0, y: 0, width: borderWidth - 1/4 * borderWidth, height: borderHeight - 1/5 * borderHeight))
myImage.image = UIImage(named: myCollection[indexPath.row])?.withRenderingMode(.alwaysTemplate)
myImage.tintColor = UIColor.groupTableViewBackground
myImage.center = CGPoint(x: tmpCell.bounds.width/2, y: tmpCell.bounds.height/2)
myImage.contentMode = .scaleAspectFit
tmpCell.contentView.addSubview(myImage)
und so weiter in der didselected und abgewählt Funktion:
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let currentCell: UICollectionViewCell?
switch collectionView {
case myCollectionView:
print("clicked")
currentCell = myCollectionView.cellForItem(at: indexPath)!
currentCell?.tintColor = UIColor.white
case colorsCollectionView:
break
default:
break
}
}
func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {
let currentCell: UICollectionViewCell?
switch collectionView {
case vehiclesCollectionView:
print("deselected")
currentCell = myCollectionView.cellForItem(at: indexPath)!
currentCell?.tintColor = UIColor.groupTableViewBackground
case colorsCollectionView:
break
default:
break
}
}
Könnte jemand sagen Ich was falsch ist? Vielen Dank im Voraus!
Lösung
Lösung Jedes Mal, wenn ich wollte, um den Farbton der Farbe aktualisieren i auf die Zelle nicht auf dem Bild zeigt wurde so basiclly nur diese Methode in oder abgewählt hinzufügen müssen:
currentCell = myCollectionView.cellForItem(at: indexPath)!
let image = currentCell?.contentView.subviews[1] as! UIImageView
image.tintColor = UIColor.white
Sie haben Recht, ich habe nicht alle Namen geändert. Ich werde das tun! – yerpy
danke für die Annahme und Upvoting! –
Es tut mir leid, aber es funktioniert nicht: C – yerpy