gpt4 book ai didi

ios - 选择时 UICollectionviewCell 图像更改

转载 作者:行者123 更新时间:2023-11-29 12:22:49 26 4
gpt4 key购买 nike

我在每个单元格中都有 UICollectionview Controller 和 UIButton。选择按钮时,我必须更改按钮 bg 图像,双击我必须再次更改它。 (单击喜欢,双击喜欢用户兴趣页面上的概念)。做这个的最好方式是什么?

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

UICollectionViewCell *cell = [interestsCollection dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];

UIButton* img=[[UIButton alloc]init];
[img setImage:[UIImage imageNamed:[imgTitleArray objectAtIndex:indexPath.row]] forState:UIControlStateNormal];
[img addTarget: self action: @selector(interestClicked:) forControlEvents: UIControlEventTouchUpInside] ;
img.frame=CGRectMake(10, 10, 60, 60);
[cell.contentView addSubview:img];

UILabel* lbl=[[UILabel alloc]initWithFrame:CGRectMake(0, 75, 80, 20)];
lbl.textAlignment = NSTextAlignmentCenter;
lbl.text=[titleArray objectAtIndex:indexPath.row];
lbl.font = [UIFont fontWithName:@"Arial" size:11];
lbl.textColor = [UIColor colorWithRed:135.0/255.0 green:135.0/255.0 blue:135.0/255.0 alpha:1.0];
[cell.contentView addSubview:lbl];

return cell;
}

最佳答案

您可以使用单双TapGesture 来处理这种情况。在受人尊敬的选择器的帮助下,您可以更改 UIButtonUIImage

这是指导您的链接。如何在 UICollectionView 上创建双击手势。借助于此,您还可以创建单个 Tap 手势。

Collection View + Double Tap Gesture

关于ios - 选择时 UICollectionviewCell 图像更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30100848/

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