I want to add a view in tableView header
. I already tried by different ways but achieved the goal. My code is given below for adding a view in headerView
.
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return arrSupport[section]
}
func tableView(_ tableView: UITableView, willDisplayHeaderView view:UIView, forSection: Int) {
if let tableViewHeaderFooterView = view as? UITableViewHeaderFooterView {
tableViewHeaderFooterView.textLabel?.textColor = UIColor.white
tableViewHeaderFooterView.textLabel?.font = UIFont.systemFont(ofSize: 16, weight: .medium)
tableViewHeaderFooterView.contentView.backgroundColor = UIColor(red: 39.0 / 255.0, green: 41.0 / 255.0, blue: 53.0 / 255.0, alpha: 1.0)
let headerView = UIView()
headerView.frame = CGRect(x: tblSupport.frame.origin.x-10, y: 10, width: tblSupport.frame.size.width-20, height: 60)
tableViewHeaderFooterView.contentView.frame = CGRect(x: 10, y: 0, width: tableView.frame.size.width-20, height: 50)
headerView.addSubview(tableViewHeaderFooterView)
}
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let headerView = UIView()
headerView.frame = CGRect(x: tblSupport.frame.origin.x-10, y: 10, width: tblSupport.frame.size.width-20, height: 60)
headerView.backgroundColor = UIColor(red: 39.0 / 255.0, green: 41.0 / 255.0, blue: 53.0 / 255.0, alpha: 1.0)
return headerView
}`
And also I want to show or hide tableview cells by clicking on respective headerview also need to decrease width of headerview like desire status
Current Status:
Desired Status: