Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Hopefully this method from the <code>UITableViewDelegate</code> protocol will get you started:</p> <p><strong>Objective-C:</strong></p> <pre><code>- (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; } </code></pre> <p><strong>Swift:</strong></p> <pre><code>func tableView(_ tableView: UITableView!, viewForHeaderInSection section: Int) -&gt; 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 } </code></pre> <p><em>Updated 2017:</em></p> <p><strong>Swift 3:</strong></p> <pre><code>func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -&gt; 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 } </code></pre> <p>Replace <code>[UIColor redColor]</code> with whichever <code>UIColor</code> you would like. You may also wish to adjust the dimensions of <code>headerView</code>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload