gpt4 book ai didi

ios - 突出显示 CollectionView 中的单元格

转载 作者:可可西里 更新时间:2023-11-01 03:39:19 25 4
gpt4 key购买 nike

我正在 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 - 突出显示 CollectionView 中的单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19562420/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com