[英]how to change collection view cell background colour when it is selected?
This code is I used if cell is selected then the background colour have to change in image view it is placed inside the collection view cell. 如果选择了单元格,则使用此代码,然后必须在图像视图中更改背景色,将其放置在集合视图单元格内。 But its not working
但是它不起作用
-(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"];
}
now its working i removed the if condition and tried using cellForItemAtIndexPath . 现在,它的工作我删除了if条件,并尝试使用cellForItemAtIndexPath。
cell = [collectionView cellForItemAtIndexPath:indexPath];
cell.img_cell.backgroundColor = [UIColor colorFromHexString:@"#ffc400"]; // high
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.