【问题标题】:How to separate Header view background color with the table view in swift如何在swift中将标题视图背景颜色与表格视图分开
【发布时间】:2020-10-17 22:12:31
【问题描述】:

所以我想从 Health App 中制作类似的内容,其中“收藏夹”标题与单元格分隔。

这是我现在的用户界面:

所以我想在第一个单元格上制作背景曲线,而不是标题标题。这可能吗?

我一直在四处寻找,但没有得到任何解决方案。这是我到目前为止创建的代码:

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    let label = UILabel()
    label.text = "Smaller Title"
    label.font = .boldSystemFont(ofSize: 22)
    label.textColor = UIColor.black
    label.backgroundColor = UIColor.clear
    label.textAlignment = .left
    label.translatesAutoresizingMaskIntoConstraints = false
    
    let headerView = UIView()
    headerView.backgroundColor = UIColor.clear
    headerView.addSubview(label)
    label.leftAnchor.constraint(equalTo: headerView.leftAnchor).isActive = true

    return headerView
}

【问题讨论】:

    标签: ios swift header tableview title


    【解决方案1】:

    这里的UITableView 有一个.white backgroundColor。尝试将UITableViewbackgroundColor 设置为.clear 并自定义UITableViewCells 以拥有.white backgroundColor

    tableView.backgroundColor = .clear
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-10
      • 2011-01-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-18
      相关资源
      最近更新 更多