UITableView - change section header color

uitableview section footer background color
uitableview section header background color storyboard
uitableviewheaderfooterview background color
uitableview header default background color
change color of tableview header
change header color in tableview swift
custom section header uitableview swift 4
uitableview section header background color ios 13

How can I change color of a section header in UITableView?

EDIT: The answer provided by DJ-S should be considered for iOS 6 and above. The accepted answer is out of date.

Hopefully this method from the UITableViewDelegate protocol will get you started:

Objective-C:

- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 
{
  UIView *headerView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)] autorelease];
  if (section == integerRepresentingYourSectionOfInterest)
     [headerView setBackgroundColor:[UIColor redColor]];
  else 
     [headerView setBackgroundColor:[UIColor clearColor]];
  return headerView;
}

Swift:

func tableView(_ tableView: UITableView!, viewForHeaderInSection section: Int) -> UIView!
{
  let headerView = UIView(frame: CGRect(x: 0, y: 0, width: tableView.bounds.size.width, height: 30))
  if (section == integerRepresentingYourSectionOfInterest) {
    headerView.backgroundColor = UIColor.redColor()
  } else {
    headerView.backgroundColor = UIColor.clearColor()
  }
  return headerView
}

Updated 2017:

Swift 3:

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?
    {
        let headerView = UIView(frame: CGRect(x: 0, y: 0, width: tableView.bounds.size.width, height: 30))
        if (section == integerRepresentingYourSectionOfInterest) {
            headerView.backgroundColor = UIColor.red
        } else {
            headerView.backgroundColor = UIColor.clear
        }
        return headerView
    }

Replace [UIColor redColor] with whichever UIColor you would like. You may also wish to adjust the dimensions of headerView.

Change tableView section header view background and text color , Is there a way to change the Section Header and footer background color func tableView(_ tableView: UITableView, willDisplayHeaderView  Questions: I have a array of headers that I use let sectionHeaderTitleArray = ["test1","test2","test3] and they are showed using func tableView[tableView: UITableView, titleForHeaderInSection section: Int) -> String? { return self.sectionHeaderTitleArray[section] as String } Now all of this works fine but I would like to modify the background color of the headers so that they are

This is an old question, but I think the answer needs to be updated.

This method does not involve defining and creating your own custom view. In iOS 6 and up, you can easily change the background color and the text color by defining the

-(void)tableView:(UITableView *)tableView 
    willDisplayHeaderView:(UIView *)view 
    forSection:(NSInteger)section

section delegate method

For example:

- (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];
}

Taken from my post here: https://happyteamlabs.com/blog/ios-how-to-customize-table-view-header-and-footer-colors/

Swift 3 / 4

func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int){
    view.tintColor = UIColor.red
    let header = view as! UITableViewHeaderFooterView
    header.textLabel?.textColor = UIColor.white
}

Any way to change the Section Header/Footer Background color , Otherwise, you can change the section header background color: When I insert​, delete rows and section size changes, sticked view does not  Changing Background Color and Section Header Text Color in a Grouped-style UITableView. While working on an iPhone application, I decided I wanted to change the colors of the background and section headers of a UITableView with the UITableViewStyleGrouped style.

Here's how to change the text color.

UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(10, 3, tableView.bounds.size.width - 10, 18)] autorelease];
label.text = @"Section Header Text Here";
label.textColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.75];
label.backgroundColor = [UIColor clearColor];
[headerView addSubview:label];

UITableview section color |Apple Developer Forums, How can I change color of a section header in UITableView? In iOS 6 and up, you can easily change the background color and the text color  (The "override" is there since i´m using the UITableViewController instead of a normal UIViewController in my project, but it´s not mandatory for changing the section header color) The text of your header will still be seen. Note that you will need to adjust the section header height. Good Luck.

You can do this if you want header with custom color:

[[UITableViewHeaderFooterView appearance] setTintColor:[UIColor redColor]];

This solution works great since iOS 6.0.

UITableView - change section header color, While working on an iPhone application, I decided I wanted to change the colors of the background and section headers of a UITableView with  The table view uses a fixed font style for section header titles. If you want a different font style, return a custom view (for example, a UILabel object) in the delegate method tableView:viewForHeaderInSection: instead. So use the below method and return your custom view (UILabel) with your choice of font.

The following solution works for Swift 1.2 with iOS 8+

override func tableView(tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {

    // This changes the header background
    view.tintColor = UIColor.blueColor()

    // Gets the header view as a UITableViewHeaderFooterView and changes the text colour
    var headerView: UITableViewHeaderFooterView = view as! UITableViewHeaderFooterView
    headerView.textLabel.textColor = UIColor.redColor()

}

Changing Background Color and Section Header Text Color in a , override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { let vw = UIView() vw.backgroundColor  Adding a header to the tableview in Interface Builder is easy, once you have your tableview drag a new view over the tableview towards the top, a blue line should appear, when it does you can place the view. See the below gif: The next thing we are going to do is change the background color of the view to blue so that it is easier to see.

How to add a section header to a table view, override func tableView(tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) { // This changes the header background view. For Swift: func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) { view.tintColor = UIColor.red let header = view as! UITableViewHeaderFooterView hea…

ios UITableView change section header color?, UITableView (grouped) and I need to change the background color going to be used is the section header height set on the UITableView  I'm very new to swift and programing for IOS but I'm trying to create an app. I want to have a UITableView where i have some headers that if you click them they will open or close depending on if t

How to change Table View header color?, A quick look at the UITableView documentation gives us the The ability, that NOT all headers-in-section could change their color — some can 

Comments
  • I really appreciate the edit RE newer iOS versions.
  • It can also help to adjust the section header size using self.tableView.sectionHeaderHeight. Otherwise, you may have trouble seeing the text you display for the section title.
  • Works fine with [UIColor xxxColor] however when I try a custom colour like ones I can get from photoshop (so using the UIColor red:green:blue:alpha:, it is just white. Am I doing something wrong?
  • Post a separate question and we'll try to help. Include source code.
  • Note that this answer (while correct) will simply return a UIView with no content.
  • This is pretty outdated information and simply creating another view isn't the best answer. The idea is to get the proper view and change the color or tint on it. The answer below using willDisplayHeaderView is a much better approach.
  • I had no idea this had even been added to the SDK. Brilliant! Absolutely the correct answer.
  • OP - Please update the accepted answer to this one. Much cleaner than the old approaches.
  • This doesn't seem to be working for me. The text color works but not the tint for the header background. I am on iOS 7.0.4
  • user1639164 ,you can use header.backgroundView.backgroundColor=[UIColor blackColor]; to set the tint for the header background.