Ios 选择集合视图单元格时,如何更改其背景颜色?
此代码是我使用的,如果选择了单元格,则背景颜色必须在图像视图中更改,它被放置在集合视图单元格中。 但它不起作用Ios 选择集合视图单元格时,如何更改其背景颜色?,ios,objective-c,uicollectionview,uicollectionviewcell,uicolor,Ios,Objective C,Uicollectionview,Uicollectionviewcell,Uicolor,此代码是我使用的,如果选择了单元格,则背景颜色必须在图像视图中更改,它被放置在集合视图单元格中。 但它不起作用 -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { if (cell.selected) { cell.img_cell.backgroundColor = [UIColor colorFr
-(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