如果选择了单元格,则会使用此代码,然后必须在图像视图中更改背景色,将其放置在集合视图单元格内。但是它不起作用
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
if (cell.selected) {
cell.img_cell.backgroundColor = [UIColor colorFromHexString:@"#ffc400"]; // highlight selection
}
else
{
cell.backgroundColor = [UIColor clearColor]; // Default color
}
NSLog(@"Selected section>> %@",[arr_images objectAtIndex:indexPath.row]);
// cell.backgroundColor=[UIColor colorFromHexString:@"#ffc400"];
}
现在,它的工作我删除了if条件,并尝试使用cellForItemAtIndexPath。
cell = [collectionView cellForItemAtIndexPath:indexPath];
cell.img_cell.backgroundColor = [UIColor colorFromHexString:@"#ffc400"]; // high
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句