首页新闻招聘找找看知识库
    • UICollectionViewCell默认情况下没有点击高亮效果, 如果想要添加高亮效果, 可以使用UICollectionViewDelegate中的下面三个方法
    #pragma mark - collectionViewCell点击高亮
    
    // 高亮时调用
    - (void)collectionView:(UICollectionView *)collectionView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath
    {
        UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
        cell.backgroundColor = [UIColor redColor];
    }
    
    // 高亮结束调用
    - (void)collectionView:(UICollectionView *)collectionView didUnhighlightItemAtIndexPath:(NSIndexPath *)indexPath
    {
        UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
        cell.backgroundColor = [UIColor whiteColor];
    }
    
    // 是否可以高亮
    - (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath
    {
        return YES;
    }

     

登录后才能评论,请先登录注册