Swift table 带有透明单元格并显示背景图像的视图
Swift table view with a cell that is transparent and shows background image
我试过了:
在 table 视图后面添加了一个橙色视图。
对于某个单元格,使用 alpha = 0 隐藏所有她的元素
尝试使单元格透明,以便它在滚动时显示 table 视图后面的橙色视图:
cell2.backgroundColor = UIColor.clearColor()
cell2.backgroundView = nil
cell2.backgroundView?.backgroundColor = UIColor.clearColor()
尝试使 table 视图透明,以便显示后面的橙色视图
tableView.backgroundColor = UIColor.clearColor()
tableView.opaque = false
tableView.backgroundView = nil
但是,当我滚动到我的单元格时,我看不到 table 视图后面的橙色视图,它只显示一个灰色单元格。
有人可以提示我还应该做什么吗?
谢谢
在您的 viewDidLoad()
中,立即添加下面的代码以设置 tableView 的背景颜色。
tableView.backgroundColor = UIColor.clearColor()
在您的 cellForRowAtIndexPath
方法中,使用类似于以下代码的内容将给定单元格的背景颜色设置为透明,其中值 2 是您要更改的单元格。
switch indexPath.row {
case 2:
cell.backgroundColor = UIColor.clearColor()
default:
print("NOT Clear")
}
我试过了:
在 table 视图后面添加了一个橙色视图。
对于某个单元格,使用 alpha = 0 隐藏所有她的元素
尝试使单元格透明,以便它在滚动时显示 table 视图后面的橙色视图:
cell2.backgroundColor = UIColor.clearColor() cell2.backgroundView = nil cell2.backgroundView?.backgroundColor = UIColor.clearColor()
尝试使 table 视图透明,以便显示后面的橙色视图
tableView.backgroundColor = UIColor.clearColor() tableView.opaque = false tableView.backgroundView = nil
但是,当我滚动到我的单元格时,我看不到 table 视图后面的橙色视图,它只显示一个灰色单元格。
有人可以提示我还应该做什么吗?
谢谢
在您的 viewDidLoad()
中,立即添加下面的代码以设置 tableView 的背景颜色。
tableView.backgroundColor = UIColor.clearColor()
在您的 cellForRowAtIndexPath
方法中,使用类似于以下代码的内容将给定单元格的背景颜色设置为透明,其中值 2 是您要更改的单元格。
switch indexPath.row {
case 2:
cell.backgroundColor = UIColor.clearColor()
default:
print("NOT Clear")
}