Where to highlight UICollectionViewCell: delegate or cell?

后端 未结 7 2553
渐次进展
渐次进展 2020-12-13 09:43

According to the Collection View Programming Guide one should handle the visual state of the cell highlights in the UICollectionViewDelegate. Like this:

7条回答
  •  情话喂你
    2020-12-13 10:10

    Well...as all of these methods are correct. I've found the way that seems like the easiest one to me. Just override the setSelected: method (for example to change background color):

    -(void)setSelected:(BOOL)selected{
        self.backgroundColor = selected?[UIColor greenColor]:[UIColor grayColor];
        [super setSelected:selected];
    }
    

    ...it works "out of the box" (even with collectionView.allowsMultipleSelection)

提交回复
热议问题