UICollectionView의 셀을 선택하거나 선택 취소 한 상태에서 이미지의 새로운 색을 설정하려고합니다. 때마다 내가 작동하는 이미지의 색조 색을 설정하지 않지만, 나는 그것의 기본 blue
색 싶지 않아요. 그래서 내가 뭐하는 거지 것은 :이미지의 색조가 변경되고 싶지 않습니다.
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
}
}
사람이 말할 수 다음 didselected 및 해제 기능에 등
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)
과 :
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
함수에서, 나는 코드로 내 이미지를 inicialazing하고 나 뭐 잘못 됐니? 미리 감사드립니다.
솔루션
솔루션 그래서 basiclly 만 선택 또는 선택 해제 방법으로이 문제를 추가 할 필요가 내가없는 이미지에 셀을 가리키고 색상의 색조를 업데이트하고 싶어 할 때마다 :
currentCell = myCollectionView.cellForItem(at: indexPath)!
let image = currentCell?.contentView.subviews[1] as! UIImageView
image.tintColor = UIColor.white
이 맞습니다. 모든 이름이 바뀌지 않았습니다. 이거 할거야! – yerpy
수락하고 upvoting 주셔서 감사합니다! –
죄송합니다. 작동하지 않습니다. C – yerpy