How can I customize the selection state of my UICollectionViewCell subclass?

前端 未结 5 1985
再見小時候
再見小時候 2021-02-01 04:02

I have a custom UICollectionViewCell subclass that overwrites initWithFrame: and layoutSubviews to setup its views. However, I\'m now trying to do two

5条回答
  •  囚心锁ツ
    2021-02-01 04:32

    In your custom UICollectionViewCell subclass, you can implement didSet on the isSelected property.

    Swift 3:

    override var isSelected: Bool {
        didSet {
            if isSelected {
                // animate selection
            } else {
                // animate deselection
            }
        }
    }
    

    Swift 2:

    override var selected: Bool {
        didSet {
            if self.selected {
                // animate selection
            } else {
                // animate deselection
            }
        }
    }
    

提交回复
热议问题