Instance Method

collectionView(_:shouldHighlightItemAt:)

Asks the delegate if the item should be highlighted during tracking.

Declaration

optional func collectionView(_ collectionView: UICollectionView, shouldHighlightItemAt indexPath: IndexPath) -> Bool

Parameters

collectionView

The collection view object that is asking about the highlight change.

indexPath

The index path of the cell to be highlighted.

Return Value

true if the item should be highlighted or false if it should not.

Discussion

As touch events arrive, the collection view highlights items in anticipation of the user selecting them. As it processes those touch events, the collection view calls this method to ask your delegate if a given cell should be highlighted. It calls this method only in response to user interactions and does not call it if you programmatically set the highlighting on a cell.

If you do not implement this method, the default return value is true.

See Also

Managing Cell Highlighting

func collectionView(UICollectionView, didHighlightItemAt: IndexPath)

Tells the delegate that the item at the specified index path was highlighted.

func collectionView(UICollectionView, didUnhighlightItemAt: IndexPath)

Tells the delegate that the highlight was removed from the item at the specified index path.