UICollectionview背景是黑色无法修改


图片描述

如图所示, 我在一个viewcontroller.view里面添加了一个collectionView和一个tableview, collectionview的背景色为黑色, 修改过background color却不管用是什么原因呢?

一些相关代码片段:
一、viewcontroller添加collection


 MagicsPhotoWaterFallLayout *layout = [[MagicsPhotoWaterFallLayout alloc] init];
layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
self.waterFallLayoutView = [[MaigcsPhotoWaterFallViewController alloc] initWithCollectionViewLayout:layout];
_waterFallLayoutView.tagId = self.tagId;
_waterFallLayoutView.viewFrame = CGRectMake(0, topBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT - topBarHeight);
[self.view addSubview:_waterFallLayoutView.view];

二、
在collectionview的viewdidload里面修改了背景色


 - (void)viewDidLoad {
[super viewDidLoad];
self.navigationController.navigationBar.translucent = NO;
self.view.backgroundColor = [UIColor whiteColor];
self.view.clipsToBounds = YES;
self.view.frame = self.viewFrame;

self.dataArray = [[NSMutableArray alloc] init];

self.refreshControl = [[UIRefreshControl alloc] init];
[self.refreshControl addTarget:self action:@selector(refreshControlValueChanged) forControlEvents:UIControlEventValueChanged];

MagicsPhotoWaterFallLayout *layout = (MagicsPhotoWaterFallLayout *)self.collectionView.collectionViewLayout;
layout.delegate = self;
self.itemWidth = layout.itemWidth;
[self.collectionView registerClass:[MagicsWaterFallViewCell class] forCellWithReuseIdentifier:waterFallCellIdentifier];
self.collectionView.delegate = self;
self.collectionView.dataSource = self;
[self.collectionView setFooterHidden:NO];

__weak typeof(self) weakSelf = self;
[self.collectionView addFooterWithCallback:^{
    [weakSelf dragResfreshAtTop:NO];
}];

[self dragResfreshAtTop:YES];

}

uicollectionview ios

Soul残舞 10 years ago

self.collectionView.backgroundColor = [uicolor whitecolor];

haner answered 10 years ago

通常这种是小错误引起的。
检查一下你的storyboard。
再检查一下你的代码。
根据你给出的代码,我只能说通常是被重新设置了背景或者是因为其他view的障眼法造成的。
先检查代码再说咯。

loli糖昔 answered 10 years ago

self.view.backgroundColor 和 self.collectionView.backgroundColor 是不一样的。

魔法少年消失君 answered 10 years ago

Your Answer