I\'m trying to change the background color of UITableViewHeaderFooterView. Although the view is appearing, the background color remains the default color. I\'m getting a log
Create UIView and set background color, then set it to self.backgroundView.
- (void)setupBackgroundColor:(UIColor *) color {
UIView *bgView = [[UIView alloc] initWithFrame:self.bounds];
bgView.backgroundColor = color;
self.backgroundView = bgView;
}
Make sure you set the backgroundColor of the contentView
for your UITableViewHeaderFooterView
:
self.contentView.backgroundColor = [UIColor whiteColor];
Then it will work.
For a clear color, I use
self.contentView.backgroundColor = [UIColor clearColor];
self.backgroundView = [UIView new];
self.backgroundView.backgroundColor = [UIColor clearColor];
It seems fine to me.
Setting the BackgroundView with clear color works fine for visible headers. If the table is scrolled to show headers at bottom ,this solution fails.
P.S.My table consists only of headers without any cells.
if you created a custom subclass of UITableViewHeaderFooterView
with xib
file then you should override setBackgroundColor
. Keep it empty.
-(void)setBackgroundColor:(UIColor *)backgroundColor {
}
And this will solve your problem.
For me I tried everything stated above but still was getting the warning "Setting the background color on UITableViewHeaderFooterView has been deprecated. Please use contentView.backgroundColor instead." then I tried this: within the xib file the background color for header view was selected to clear color instead of default once I changed it to default the warning went away.