ios - 背景颜色自定义uicollectionview

标签 ios uicollectionview

我有一个 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 也使用非常基本的自定义布局。 图片中显示的内容的摘录:

enter image description here

Collection View 显示带有数字的单元格。在 Collection View 下方有一个背景,由于单元格的颜色为白色而未显示。 任何提示表示赞赏。谢谢。

最佳答案

已解决。 问题出在自定义单元格的呈现中。我使用了一种设置单元格背景颜色的方法(一种丢失的方法......)。对于非自定义单元格,我问题中的代码是正确的。

关于ios - 背景颜色自定义uicollectionview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19050304/

相关文章:

swift - 将现有 View 添加到collectionview-cell

ios - 在 UICollectionViewCell 的 subview 上调用 removeFromSuperview 在第一次加载时不起作用,仅当单元格被重用时

ios - 如何从另一个 Controller 启用滚动?

ios - 从 JSON 数组到 UICollectionView 的多个图像

ios - 设置永久数组元素

ios - 在 UIView 的 Accessibility Rotor VoiceOver 中启用链接

ios - Swift 4.2 已经在文档中了吗?

ios - 以编程方式向已以编程方式添加到表格单元格的标签添加约束

ios - 在 UIImageView 中显示事件指示器

ios - 查看<(空):0x0> does not conform to UITextInput protocol when tapping Return button on keyboard