I am trying to add padding to this custom header view (an image).
The table is static content cells
and I am only adding an image to the first section.
I tried to follow this link but was unsuccessful.
I am trying to add some top and bottom padding in the header view.
I tried this to no luck:
override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
if section == 0 {
var header = tableView.tableHeaderView
let image = UIImage(named: "Placeholder") // is 121x121
let imageView = UIImageView(frame: CGRect(x: 0, y: 20, width: tableView.frame.width, height: tableView.sectionHeaderHeight))
imageView.image = image
imageView.contentMode = .scaleAspectFit
header = imageView
return header
}
return nil
}
I am also defining the header height in the delegate:
override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
if section == 0 {
return 125.0
}
return 44.0
}
The result is the same with no padding.
Any help would be appreciated
I have also tried to add the imageView to the header subview which results in the whole image disappearing.