如何更改TableViewCell的alpha而不更改文本的alpha?

时间:2016-06-23 21:27:29

标签: ios swift uitableview tableview

我正在使用tableViewController处理应用程序。我想在我的表格视图单元格下面添加一个背景图片。我想让表视图单元格透明,以便我的整个表视图可以有自定义背景。我怎样才能做到这一点?

由于

3 个答案:

答案 0 :(得分:1)

首先,您可以设置此视图层次结构:

-View
--UIImageView  // will be used as the background image of tableview
--UITableView

然后在viewDidLoad中设置如下属性:

myTableView.backgroundColor = UIColor.clearColor()
myTableView.backgroundView.backgroundColor = UIColor.clearColor()

同样可以为UITableViewCell做。为此,您需要访问cell.contentView属性。

答案 1 :(得分:0)

viewDidLoad()

中试试
let imageView = UIImageView()
imageView.frame = tableView.bounds
imageView.image = UIImage(named: "BG")
tableView.backgroundView = imageView

cellForRowAtIndexPath中:添加以下行:

cell.backgroundColor = UIColor.clearColor()

答案 2 :(得分:0)

在不影响其子视图的情况下,无法更改超视图的alpha。 但是,您可以更改其背景颜色以实现目标。

tableView:willDisplayCell:forRowAtIndexPath:做dis

cell.backgroundColor = UIColor.clearColor()

代码已置于此方法中 tableView:cellForRowAtIndexPath:

相关问题