IOS:在UICollectionView Cell上添加叠加图像

时间:2013-08-13 16:36:40

标签: iphone ios uicollectionview

我正在使用UICollectionView生成图片库。我在UIImage UICollectionView内使用了Cell来加载图片。我需要通过长按选择UICollectionView Cell(而不是单击)。

1 个答案:

答案 0 :(得分:2)

只需选择didSelectItemAtIndexPath委托回调,抓住单元格,然后将图片添加为子视图。

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    YourCollectionViewCell *cell = (YourCollectionViewCell*)[collectionView cellForItemAtIndexPath:indexPath];
    UIImageView *yourImageView = [[UIImageView alloc]initWithFrame:CGRectMake(x, y, width, height)];//whichever frame you want it to appear at
    yourImageView.image = [UIImage imageNamed:@"yourImageName"];//set the image
    [cell.yourBaseImage addSubview:yourImageView];//or add it to whatever part of the cell you want
}

或者,只需在Storyboard中设置隐藏的imageView即可。然后取消隐藏它并将图像设置在didSelectItemAtIndexPath内。