【发布时间】:2014-06-29 04:12:26
【问题描述】:
我在为 UICollectionViewCell 和 UICollectionReusableView 对象设置背景颜色时遇到问题。它在 iOS 7 上运行没有问题,但在 iOS 6 上我得到的只是白色背景。
在我UICollectionView的数据源中,我在这个方法中设置了背景颜色:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
此代码仅适用于 iOS 7:
cell.contentView.backgroundColor = [UIColor redColor];
这是我已经尝试让它在 iOS 6 上运行的内容:
UIColor *backgroundColor = [UIColor redColor];
cell.backgroundColor = backgroundColor;
cell.backgroundView = [[UIView alloc] initWithFrame:cell.bounds];
cell.backgroundView.backgroundColor = backgroundColor;
cell.layer.backgroundColor = [backgroundColor CGColor];
cell.backgroundView.layer.backgroundColor = [backgroundColor CGColor];
cell.contentView.layer.backgroundColor = [backgroundColor CGColor];
不幸的是,没有成功。我很困惑,真的不知道我在这里错过了什么。
除了这个问题,其他一切都按预期工作,我的UICollectionView 在 iOS 7 和 iOS 6 上都能正确显示单元格。
我使用的代码可以在 GitHub 上找到,作为我制作的库的一部分。如果您需要有关我的实现的更多信息,请在此处查看:DRCollectionViewTableLayout-iOS。该存储库包含带有 UICollectionView 的演示项目。在 iOS 7 上,单元格具有随机颜色,在 iOS 6 上,所有单元格都有白色背景。
【问题讨论】:
标签: ios ios6 uicollectionview uicollectionviewcell