Transparent UITableViewHeaderFooterView
Please forgive my inability to use stackoverflow....
Here's how I managed to implement it, using both these UITableviewDelegate methods:
- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section {
if ([view isMemberOfClass:[UITableViewHeaderFooterView class]]) {
((UITableViewHeaderFooterView *)view).backgroundView.backgroundColor = [UIColor clearColor];
}
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UITableViewHeaderFooterView *feedHeaderView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"HeaderIdentifier"];
//Other customizations
return feedHeaderView;
}
Hope that helps, took me forever to figure out. It seems the backgroundView is not created in the init so the color cannot be overridden there.
UPDATE: apparantly, my previously suggested answer wasn't working anymore in iOS 13+, here's what I would get in console -
Setting the background color on UITableViewHeaderFooterView has been deprecated. Please set a custom UIView with your desired background color to the backgroundView property instead.
Further, looking at some comments here, setting tintColor
to .clear
did the trick.
func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
view.tintColor = .clear
}
Have fun coding :)
Make a view which has transparent background color and assign it to the UITableViewHeaderFooterView's backgroundView property.
class HeaderView: UITableViewHeaderFooterView{
override
init(reuseIdentifier: String?){
super.init(reuseIdentifier: reuseIdentifier)
self.backgroundView = UIView()
self.backgroundView!.backgroundColor = UIColor.clearColor()
}
required
init(coder: NSCoder){
super.init(coder: coder)
}
override
init(frame: CGRect){
super.init(frame: frame)
}
}