我實際上使用表視圖來顯示一些數據,我重寫willDisplayHeaderView
爲標題添加自定義樣式。除了我無法更改標題標題的背景顏色外,所有工作都很好。這裏是我的代碼:如何使透明標題標題的tableview恩Swift ios
override func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int)
{
view.backgroundColor = UIColor.clear
let title = UILabel()
title.font = UIFont(name: "System", size: 22)
title.textColor = UIColor(rgba: "#BA0B23")
title.backgroundColor = UIColor.clear
let header = view as! UITableViewHeaderFooterView
header.textLabel?.font=title.font
header.backgroundColor = UIColor.clear
header.textLabel?.textColor=title.textColor
header.textLabel?.textAlignment = NSTextAlignment.center
let sepFrame = CGRect(x: 0, y: header.frame.size.height-1, width: header.frame.size.width, height: 1)
let seperatorView = UIView(frame: sepFrame)
seperatorView.backgroundColor = UIColor(rgba: "#BA0B23")
header.addSubview(seperatorView)
}
我不知道我做錯了什麼,一些幫助將不勝感激。謝謝
如何獲得'headerView'? – Snoobie