【问题标题】:Swift table view with a cell that is transparent and shows background image带有透明单元格并显示背景图像的 Swift 表格视图
【发布时间】:2016-05-19 14:45:05
【问题描述】:

我已经尝试过这样做:

  • 在表格视图后面添加了一个橙色视图。

  • 对于某个单元格隐藏 alpha = 0 的所有元素

  • 试图使单元格透明,以便在滚动时在表格视图后面显示橙色视图:

    cell2.backgroundColor = UIColor.clearColor()
    cell2.backgroundView = nil
    cell2.backgroundView?.backgroundColor = UIColor.clearColor()
    
  • 试图使表格视图透明,以便显示后面的橙色视图

    tableView.backgroundColor = UIColor.clearColor()
    tableView.opaque = false
    tableView.backgroundView = nil
    

但是当我滚动到我的单元格时,我看不到表格视图后面的橙色视图,它只显示一个灰色的单元格。

谁能给我任何提示,告诉我我还应该做什么?

谢谢

【问题讨论】:

    标签: swift tableview transparency tableviewcell


    【解决方案1】:

    在您的viewDidLoad() 中,在下面添加代码以设置 tableView 的背景颜色。

    tableView.backgroundColor = UIColor.clearColor()
    

    在您的 cellForRowAtIndexPath 方法中,使用类似于以下代码的内容将给定单元格的 backgroundColor 设置为透明,其中值 2 是您要更改的单元格的行.

    switch indexPath.row {
    case 2:
        cell.backgroundColor = UIColor.clearColor()
    default:
        print("NOT Clear")
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-04-17
      • 2015-03-12
      • 1970-01-01
      • 2011-09-13
      • 2023-01-30
      • 2012-02-15
      • 1970-01-01
      相关资源
      最近更新 更多