ios - 点击集合查看单元格更改图像
<p><p>我有一个集合单元格,想在触摸时更改图像,然后再返回,我应该如何构造它?</p>
<p>突出显示后(在下面效果很好),我希望它在再次触摸时返回到旧图像。谢谢你。在 viewWillDissapear 中,我想知道突出显示了哪些单元格。</p>
<pre><code>-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
UIImage *backGround =;
UIImageView *av = [ initWithFrame:CGRectMake(0, 0, backGround.size.width, backGround.size.height)];
av.backgroundColor = ;
av.opaque = NO;
av.image = backGround;
[ setBackgroundView:av];
[.backgroundView setTag:1];
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>创建 CustomCell - UICollectionViewCell 的子类。自定义 init 如下</p>
<pre><code>//CustomCell.m
- (id)initWithFrame:(CGRect)frame
{
self = ;
if (self) {
backgroundImageView.image = ;
highlightImageView.image = ;
self.backgroundView = backgroundImageView;
_isHighlight = -1;
}
return self;
}
-(void)tapToChangeBackGround{
self.isHighlight = -self.isHighlight;
if (self.isHighlight==1) {
self.backgroundView = highlightImageView;
}
else{
self.backgroundView = backgroundImageView;
}
}
//didSelect
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
CustomCell *cell = (CustomCell *);
;
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - 点击集合查看单元格更改图像,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/14266312/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/14266312/
</a>
</p>
页:
[1]