UICollectionViewCell點擊高亮效果(附帶效果GIF)


首先效果如下:

背景是這樣的:UI上使用的是UICollectionView,所以后面會使用它的協議方法完成。

實現思路是這樣的:高亮狀態+點擊后短時間內保持顏色變化

實現的代碼參考如下:

// Cell被點擊后短時間內保持顏色的變化
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
WSFEvaluateTagItem
*cell = (WSFEvaluateTagItem *)[collectionView cellForItemAtIndexPath:indexPath]; cell.backgroundColor = [UIColor blueColor]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ cell.backgroundColor = [UIColor whiteColor]; }); } // 長按的情況下要實現高亮狀態下的顏色保持 - (void)collectionView:(UICollectionView *)collectionView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath{ WSFEvaluateTagItem *cell = (WSFEvaluateTagItem *)[collectionView cellForItemAtIndexPath:indexPath]; cell.backgroundColor = [UIColor blueColor]; }
- (void)collectionView:(UICollectionView *)collectionView didUnhighlightItemAtIndexPath:(NSIndexPath *)indexPath{ WSFEvaluateTagItem *cell = (WSFEvaluateTagItem *)[collectionView cellForItemAtIndexPath:indexPath]; cell.backgroundColor = [UIColor whiteColor]; }
- (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath{ return YES; }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM