2013-09-27 160 views
3

我有一个UICollectionView它包含自定义UICollectionViewCell。收集视图具有背景图像。 我会显示背景图像,但集合视图(或其单元格)始终有一个白色背景,可防止显示背景图像。 下面是代码:背景色自定义uicollectionview

-(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。集合视图也使用非常基本的自定义布局。 一个什么在事先知情所示excertp:

enter image description here

集合视图显示细胞数。在收集视图下面有一个背景,因为单元格的颜色是白色而没有显示。 任何暗示赞赏。谢谢。

+0

尝试使用[cell.backgroundView addSubView .. – iPatel

+0

addSubView ...要添加什么? – giuseppe

+0

UIImageView就可以了。 – iPatel

回答

0

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

-1

您还可以通过为UICollectionView设置backgroundview来为您的自定义UICollectionView设置背景颜色。 UIView * blueView = [[UIView alloc] init]; blueView.backgroundColor = [UIColor blueColor]; self.collectionView.backgroundView = blueView;