UICollectionview背景是黑色无法修改

发布于 2022-08-30 00:31:22 字数 1851 浏览 51 评论 0

图片描述

如图所示, 我在一个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];

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

尤怨 2022-09-06 00:31:22

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

离鸿 2022-09-06 00:31:22

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

丘比特射中我 2022-09-06 00:31:22

self.collectionView.backgroundColor = [uicolor whitecolor];

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文