I have a simple dilemma. I have a UICollectionViewController in my app that displays saved quizzes. I have the loading right, but I want it to move detect a tap on one of them and then do logic to load it into the main VC. I would like the selection to be similar to a UITableViewCell where it highlights it for a second and then unhighlights it. I am using a subclassed UICollectionViewCell if that helps.
An object that manages an ordered collection of data items and presents them using customizable layouts.
In order for the highlighting to show, you can subclass your cells like this:
import UIKit
class CustomCell: UICollectionViewCell {
override func awakeFromNib() {
super.awakeFromNib()
let backgroundView = UIView(frame: CGRectZero)
backgroundView.backgroundColor = UIColor.blueColor()
self.selectedBackgroundView = backgroundView
}
}
From the docs for UICollectionViewCell
:
You can use this view to give the cell a custom appearance when it is selected. When the cell is selected, this view is layered above the backgroundView and behind the contentView.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With