How to select and highlight a UICollectionView, for example, a UITableViewCell?

I have a simple dilemma. I have a UICollectionViewController in my application that displays saved quizzes. I have the right to boot, but I want it to move, detect a crane on one of them, and then do the logic to load it into the main VC. I would like the selection to look like a UITableViewCell, where it selects it for a second and then selects it. I use subclasses of UICollectionViewCell if this helps.

+4
source share
3 answers

In order for the highlight to appear, you can subclass your cells as follows:

import UIKit

class CustomCell: UICollectionViewCell {

    override func awakeFromNib() {
        super.awakeFromNib()

        let backgroundView = UIView(frame: CGRectZero)

        backgroundView.backgroundColor = UIColor.blueColor()

        self.selectedBackgroundView = backgroundView
    }
}

UICollectionViewCell:

, , . , backgroundView .

+4

UICollectionViewCell

@property(nonatomic, getter=isHighlighted) BOOL highlighted;

UICollectionViewCell cellForItemAtIndexPath:

0

UITableView, UICollectionView , . U , . U Apple. https://developer.apple.com/library/ios/documentation/UIKit/Reference/UICollectionView_class/ , .

***** EDITED ***** You can also refer to this. Why doesn't the UICollectionView UICollectionViewCell highlight the user by touch? Happy Coding .. :)

0
source

Source: https://habr.com/ru/post/1612342/


All Articles