ios – 在CollectionView中突出显示单元格

前端之家收集整理的这篇文章主要介绍了ios – 在CollectionView中突出显示单元格前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在iOS中构建一个应用程序,我希望我的CollectionView中的单元格在触摸时突出显示,就像普通按钮一样.如何在didSelectItemAtIndexPath:(NSIndexPath *)indexPath方法中实现此目的?

解决方法

尝试这样的事情:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    .....
    if (cell.selected) {
        cell.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:153/255.0 alpha:1]; // highlight selection
    }
    else
    {
        cell.backgroundColor = [UIColor clearColor]; // Default color
    }
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    UICollectionViewCell* cell = [collectionView  cellForItemAtIndexPath:indexPath];
    cell.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:153/255.0 alpha:1]; //     //cell.lblImgTitle.text = @"xxx";
}

- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath{
    UICollectionViewCell* cell = [collectionView  cellForItemAtIndexPath:indexPath];
    cell.backgroundColor = [UIColor clearColor];
}

猜你在找的iOS相关文章