我有一个 UICollectionView
,其中包含自定义 UICollectionViewCell
。 Collection View 有一个背景图像。
我会显示背景图像,但 Collection View (或其单元格)始终为白色背景,这会阻止我的背景图像显示。
这是代码:
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
AgendaCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:agendaCellIdentifier forIndexPath:indexPath];
cell.delegate = self;
cell.layer.borderWidth=0.0f;
cell.layer.backgroundColor = [UIColor clearColor].CGColor;
cell.contentView.layer.backgroundColor = [UIColor blackColor].CGColor;
cell.layer.shouldRasterize = YES;
cell.layer.rasterizationScale = [UIScreen mainScreen].scale;
[cell setCurrentDateAtIndex:([indexPath row]) date:currentMonth events:events];
return cell;
}
AgendaCollectionCell
非常简单:我使用 IB 制作了一个单元格,并将所有背景图像设置为 clearColor。 Collection View 也使用非常基本的自定义布局。
图片中显示的内容的摘录:
Collection View 显示带有数字的单元格。在 Collection View 下方有一个背景,由于单元格的颜色为白色而未显示。 任何提示表示赞赏。谢谢。
最佳答案
已解决。 问题出在自定义单元格的呈现中。我使用了一种设置单元格背景颜色的方法(一种丢失的方法......)。对于非自定义单元格,我问题中的代码是正确的。
关于ios - 背景颜色自定义uicollectionview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19050304/