Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As the documentation says, you can rely on <code>highlighted</code> property to be changed while the cell is highlighted. For example the following code will make the cell red when highlighted (not its subviews though):</p> <pre><code>- (void)setHighlighted:(BOOL)highlighted { [super setHighlighted:highlighted]; [self setNeedsDisplay]; } - (void)drawRect:(CGRect)rect { [super drawRect:rect]; if (self.highlighted) { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetRGBFillColor(context, 1, 0, 0, 1); CGContextFillRect(context, self.bounds); } } </code></pre> <p>And if you <strong>add</strong> something like this the background will become purple (red + opaque blue):</p> <pre><code>- (void)collectionView:(UICollectionView *)colView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath { UICollectionViewCell *cell = [colView cellForItemAtIndexPath:indexPath]; cell.contentView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:1 alpha:0.5]; } - (void)collectionView:(UICollectionView *)colView didUnhighlightItemAtIndexPath:(NSIndexPath *)indexPath { UICollectionViewCell *cell = [colView cellForItemAtIndexPath:indexPath]; cell.contentView.backgroundColor = nil; } </code></pre> <p>So you can use both together (not necessarily both changing the cell appearance). The difference is that with delegate methods you also have <code>indexPath</code>. It might be used to create multi-selection (you will use this methods together with selection delegate methods), to show some preview while the cell is highlighted, to show some animation with other views... There's quite a few appliance for this delegate methods in my opinion.</p> <p>As a conclusion, I would leave the cell appearance to be handled by the cell itself and use delegate methods to let controller make something cool in the same time.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload