ios – 带图像的UICollectionView单元格,单击更改背景

ios – 带图像的UICollectionView单元格,单击更改背景,第1张

概述我有一个带有Custom CollectionView Cells的UICollectionView.在每个Cell上都有一个 Image,它与整个Cell一样大.现在我想在用户触摸Cell时突出显示Cell.首先,我尝试使用以下委托方法: - (void)collectionView:(UICollectionView *)collectionView didHighlightItemAtInd 我有一个带有Custom CollectionVIEw Cells的UICollectionVIEw.在每个Cell上都有一个 Image,它与整个Cell一样大.现在我想在用户触摸Cell时突出显示Cell.首先,我尝试使用以下委托方法:

- (voID)collectionVIEw:(UICollectionVIEw *)collectionVIEw dIDHighlightItemAtIndexPath:(NSIndexPath *)indexPath{UICollectionVIEwCell* cell = [self.collectionVIEw cellForItemAtIndexPath:indexPath];cell.contentVIEw.backgroundcolor = [UIcolor redcolor];}- (voID)collectionVIEw:(UICollectionVIEw *)collectionVIEw dIDUnhighlightItemAtIndexPath:(NSIndexPath *)indexPath{UICollectionVIEwCell *cell = [self.collectionVIEw cellForItemAtIndexPath:indexPath];cell.contentVIEw.backgroundcolor = [UIcolor clearcolor];}

但没有任何事情发生.我删除了细胞中的图像,它完美地工作.但随着图像没有任何反应!我还可以做些什么?

解决方法 如果您有CustomCell,则必须具有CustomCell.m(实现文件).在这个文件中添加这个,对我来说是简单的方法:

-(voID)setHighlighted:(BOol)highlighted{    if (highlighted)    {        self.layer.opacity = 0.6;        // Here what do you want.    }    else{        self.layer.opacity = 1.0;        // Here all change need go back    }}
总结

以上是内存溢出为你收集整理的ios – 带图像的UICollectionView单元格,单击更改背景全部内容,希望文章能够帮你解决ios – 带图像的UICollectionView单元格,单击更改背景所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1008501.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-22
下一篇2022-05-22

发表评论

登录后才能评论

评论列表(0条)

    保存