Ios 如何在swift中将标题视图背景色与表格视图分开
所以我想从健康应用程序中制作类似的东西,“收藏夹”标题与单元格分开 以下是我现在的UI: 所以我想在第一个单元格上绘制背景曲线,而不是标题。可能吗 我一直在四处寻找,没有找到任何解决办法。以下是我迄今为止创建的代码:Ios 如何在swift中将标题视图背景色与表格视图分开,ios,swift,header,tableview,title,Ios,Swift,Header,Tableview,Title,所以我想从健康应用程序中制作类似的东西,“收藏夹”标题与单元格分开 以下是我现在的UI: 所以我想在第一个单元格上绘制背景曲线,而不是标题。可能吗 我一直在四处寻找,没有找到任何解决办法。以下是我迄今为止创建的代码: func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { let label = UILabel() label.text = &q
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
}
这里的
UITableView
有一个.white
背景色
。尝试将UITableView
的backgroundColor
设置为。清除并自定义UITableView单元格
,使其具有.white
backgroundColor
tableView.backgroundColor = .clear