UICollectionView 修改点击后颜色

博客介绍了如何修改UICollectionView在被点击后显示的默认透明色,重点在于正确设置背景色的代码实现,以达到展示特定颜色的效果。
摘要由CSDN通过智能技术生成

一般UICollectionView点击后会显示默认的透明色,希望修改为特定的颜色,最终发现是设置背景色的view设置错了,应该是:[cell.contentView setBackgroundColor:[UIColor redColor]];
具体代码如下:

- (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}
- (void)collectionView:(UICollectionView *)collectionView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath{
    UICollectionViewCell* cell = [collectionView cellForItemAtIndexPath:indexPath];
    //设置(Highlight)高亮下的颜色
    [cell.contentView setBackgroundColor:[UIColor redColor]];
}

- (
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值