【问题标题】:Swift 2.2 UITableViewHeaderFooterView transparentSwift 2.2 UITableViewHeaderFooterView 透明
【发布时间】:2016-08-04 16:59:28
【问题描述】:

我正在尝试为 TableViewHeader 设置透明背景,但没有成功。 首先,想知道有没有可能?

这就是我所做的

func tableView(tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
   let header: UITableViewHeaderFooterView = view as! UITableViewHeaderFooterView 
   header.contentView.backgroundColor = UIColor.clearColor()
}

我的最终目标是在我的 uitableview 下添加一个 UIView,它将托管一个 GMSMapView 并具有一个大小为 100 像素的透明 HeaderView。

有什么帮助吗? 谢谢

【问题讨论】:

    标签: swift uitableview swift2 uitableviewsectionheader


    【解决方案1】:

    您需要执行以下步骤

    1) 在 storyboard 中添加 headerfooterview 到 tableview

    2)鉴于确实加载写了下面的代码

    tableView.registerClass(HeaderView.self, forHeaderFooterViewReuseIdentifier: "HeaderView")
    headerView = tableView.dequeueReusableHeaderFooterViewWithIdentifier("headerView") as? HeaderView
    

    3) 添加tableview委托方法

     func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
            return 110;
    }
    
    func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        headerView.backgroundColor = UIColor.clearColor()
        return headerView;
    }
    

    希望对你有帮助

    【讨论】:

      【解决方案2】:

      要遵循的步骤:

      1) 将一个 UIView 从对象库中拖放到 tableview 的顶部以制作 tableview 标题。

      2) 在 Tableview 控制器中创建视图的 IBOutlet。

      3)最后调用这个 UITableview 委托方法

      override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
      
              yourHeaderView.backgroundColor = UIColor.clearColor()
              return yourHeaderView
      
          }
      

      // 当你需要做一个透明的页脚视图时调用它

      override func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
              footerView.backgroundColor = UIColor.clearColor()
              return footerView
          }
      

      【讨论】:

        【解决方案3】:

        //透明你的表格视图部分标题:

        //在 Swift 5 中

        func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {

        view.tintColor = UIColor.clear

        }

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-03-23
          • 1970-01-01
          • 1970-01-01
          • 2016-12-20
          • 1970-01-01
          • 2012-09-23
          相关资源
          最近更新 更多