According to the Collection View Programming Guide one should handle the visual state of the cell highlights in the UICollectionViewDelegate
. Like this:
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;