Class

UITableViewHeaderFooterView

The UITableViewHeaderFooterView class implements a reusable view that can be placed at the top or bottom of a table section. You use headers and footers to display additional information for that section.

Overview

You can use this class as-is without subclassing in most cases. If you have custom content to display, create the subviews for your content and add them to the view in the contentView property. You can also assign an optional background view to the backgroundView property. If you do not want to add custom subviews, you can use the textLabel property to display some descriptive text in the view. You can also implement tableView(_:titleForHeaderInSection:): (or tableView(_:titleForFooterInSection:)) to display a custom section title without needing to use custom subviews. Tables in grouped style additionally support the detailTextLabel property.

To make the table view aware of your header or footer view, you need to register it. You do this using the register(_:forHeaderFooterViewReuseIdentifier:) or register(_:forHeaderFooterViewReuseIdentifier:) method of UITableView.

Symbols

Initializing the View

init(reuseIdentifier: String?)

Initializes a header/footer view with the specified reuse identifier.

Accessing the Content Views

var contentView: UIView

The content view of the header or footer.

var backgroundView: UIView?

The background view of the header or footer.

Managing View Reuse

var reuseIdentifier: String?

A string used to identify a reusable header or footer.

func prepareForReuse()

Prepares a reusable header or footer view for reuse by the table.

Accessing the Default View Content

var textLabel: UILabel?

A primary text label for the view.

var detailTextLabel: UILabel?

A detail text label for the view.

var tintColor: UIColor!

The tint color of the view.