Where to highlight UICollectionViewCell: delegate or cell?

后端 未结 7 2524
渐次进展
渐次进展 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条回答
  •  -上瘾入骨i
    2020-12-13 10:18

    As taken directly from UICollectionViewCell.h - overriding both setSelected and setHighlighted are correct. Depending upon your situation you might consider assigning custom views to backgroundView and selectedBackgroundView which are swapped automatically on selection.

    // Cells become highlighted when the user touches them.
    // The selected state is toggled when the user lifts up from a highlighted cell.
    // Override these methods to provide custom UI for a selected or highlighted state.
    // The collection view may call the setters inside an animation block.
    @property (nonatomic, getter=isSelected) BOOL selected;
    @property (nonatomic, getter=isHighlighted) BOOL highlighted;
    
    // The background view is a subview behind all other views.
    // If selectedBackgroundView is different than backgroundView, it will be placed above the background view and animated in on selection.
    @property (nonatomic, retain) UIView *backgroundView;
    @property (nonatomic, retain) UIView *selectedBackgroundView;
    

提交回复
热议问题