func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! PlaceCollectionViewCell
//let imageView = UIImageView()
//cell.backgroundColor = UIColor(colorLiteralRed: 0.278, green: 0.694, blue: 0.537, alpha: 1.00)
cell.layer.borderWidth = 0.5
cell.layer.borderColor = UIColor(colorLiteralRed: 0.278, green: 0.694, blue: 0.537, alpha: 1.00).cgColor
//cell.placeLabel.tintColor = UIColor(colorLiteralRed: 0.278, green: 0.694, blue: 0.537, alpha: 1.00).cgColor
cell.layer.cornerRadius = 40
cell.layer.masksToBounds = true
print("places\(indexPath.row)")
//cell.placeLabel.text = places[indexPath.row] as! String
cell.placeLabel.text = places[indexPath.row]
cell.placeLabel.textColor = UIColor(colorLiteralRed: 0.278, green: 0.694, blue: 0.537, alpha: 1.00)
// code for VIew
let view = UIView(frame: cell.bounds)
//Set background color that you want
view.backgroundColor = UIColor(colorLiteralRed: 0.278, green: 0.694, blue: 0.537, alpha: 1.00)
cell.selectedBackgroundView = view
return cell
我在集合視圖單元格中有一個圖像。我只需要單擊單元格時顯示該圖像。我們必須在cellforRowat索引路徑中執行此操作嗎?如何在UICollection View單元中顯示圖像,同時單擊swift ios中的單元格?
//Custom class code:
@IBOutlet weak var tickImageView: UIImageView!
@IBOutlet weak var placeViewBtn: UIButton!
@IBOutlet weak var placeLabel: UILabel!
@IBOutlet weak var imageView: UIImageView!
override func layoutSubviews() {
}
override func awakeFromNib() {
self.imageView.layer.cornerRadius = self.imageView.frame.size.width/2
self.imageView.layer.masksToBounds = true
super.awakeFromNib()
// Initialization code
}
添加了自定義類代碼。我想要顯示上面已經聲明的ticMark圖像。
你必須使用didSelectRowAtIndexPath方法方法 –
你說的意思是「我在收集觀察單元的圖像。我只需要顯示圖像時,我點擊單元格。」? –
@NiravD其實它是一個「嘀嗒」的圖像。當我點擊collectionview中的一個單元格時,該tickmark圖像應該只顯示在該單元格上。 –