如何在 Swift 中使 UICollection 视图的背景透明而不使其中的单元格透明

las*_*302 7 ios uicollectionview uicollectionviewcell uicollectionviewlayout swift

我有一个集合视图,当然我也有单元格。如果在属性检查器中我将集合视图的 alpha 更改为 0,其中的单元格也会变得透明。有没有办法使集合视图的背景透明,以便它后面的图像可见?

Kas*_*ani 9

在 Swift 3 中使用:

collectionView.backgroundColor = UIColor.clear.withAlphaComponent(0)
Run Code Online (Sandbox Code Playgroud)


Res*_*der 7

您可以将单元格颜色更改为清除并将背景设置为 nil 以查看 collectionView 下方的内容。像这样:

  collectionview.backgroundView = nil;
  collectionview.backgroundColor = [UIColor clearColor];
Run Code Online (Sandbox Code Playgroud)


Sim*_*lin 4

AUICollectionViewCell的背景默认为透明。只需在界面生成器或子类中使用以下命令为单元格设置背景颜色:

self.backgroundColor = UIColor.WhiteColor()
Run Code Online (Sandbox Code Playgroud)