- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section
{
// Background color
view.tintColor = [UIColor blackColor];
// Text Color
UITableViewHeaderFooterView *header = (UITableViewHeaderFooterView *)view;
[header.textLabel setTextColor:[UIColor whiteColor]];
// Another way to set the background color
// Note: does not preserve gradient effect of original header
// header.contentView.backgroundColor = [UIColor blackColor];
}
Alex Reynolds
希望这个从UITableViewDelegate协议里得到的方法可以对你有所帮助:
使用任何你喜欢UIColor代替[UIColor redColor]。你可能还希望调整headerView的尺寸。
DoctorG
这是改变文本颜色的方法:
whyoz
不要忘记从委托添加这段代码,否则在某些情况下视图将被切断或者出现在table后面,相对于视图/标签的高度。
Leszek Żarna
如果你想自定义header颜色,可以这样做:
这个方法在iOS 6.0.以上都很好用。
Maulik
这是在标题视图添加图片的方法:
William Jockusch
如果你不想建立自定义视图,你也可以这样改变颜色(需要在iOS6里):
Dj S
这是常见的问题,我认为答案需要更新一下。
这个方法不涉及定义和创建自定义视图。在iOS 6以上,你可以通过以下方法轻松改变背景色和文本色:
委托方法
例如:
orbv
通过UITableViewHeaderFooterView设置背景色的方法已经被废弃了。请用contentView.backgroundColor代替。