UICollectionView 类似UIButton点击变灰,松开恢复

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

//设置点击高亮和非高亮效果!

- (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath{

 

    NSLog(@"shouldHighlightItemAtIndexPath");

    return YES;

}

 

-  (void)collectionView:(UICollectionView *)collectionView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath{

    

    NSLog(@"didHighlightItemAtIndexPath");

    UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];

    [cell setBackgroundColor:UIColorFromRGB(0xC9C9C9)];

}

 

- (void)collectionView:(UICollectionView *)collectionView didUnhighlightItemAtIndexPath:(NSIndexPath *)indexPath{

    

    NSLog(@"didUnhighlightItemAtIndexPath");

    

    UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];

    [cell setBackgroundColor:[UIColor whiteColor]];

}

 

转载于:https://my.oschina.net/zhuzhu1223/blog/751830

你可能感兴趣的:(UICollectionView 类似UIButton点击变灰,松开恢复)