【问题标题】:how to change collection view cell background colour when it is selected?选择时如何更改集合视图单元格背景颜色?
【发布时间】:2015-07-18 05:03:18
【问题描述】:

如果选择了单元格,则我使用此代码,然后背景颜色必须在图像视图中更改,它位于集合视图单元格内。 但它不起作用

-(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"];
  }

【问题讨论】:

    标签: ios objective-c uicollectionview uicollectionviewcell uicolor


    【解决方案1】:

    现在它的工作我删除了 if 条件并尝试使用 cellForItemAtIndexPath 。

    cell = [collectionView cellForItemAtIndexPath:indexPath];
    
            cell.img_cell.backgroundColor = [UIColor colorFromHexString:@"#ffc400"]; // high
    

    【讨论】:

      猜你喜欢
      • 2022-12-20
      • 2015-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多