UITableViewCell class defines the attributes and behavior of the cells that appear in
UITableView objects. This class includes properties and methods for setting and managing cell content and background (including text, images, and custom views), managing the cell selection and highlight state, managing accessory views, and initiating the editing of the cell contents.
- iOS 2.0+
- tvOS 2.0+
When creating cells, you can customize them yourself or use one of several predefined styles. The predefined cell styles are the simplest option. With the predefined styles, the cell provides label and image subviews whose positions and styling are fixed. All you have to do is provide the text and image content to go into those fixed views. To use a cell with a predefined style, initialize it using the
init(style:reuseIdentifier:) method or configure the cell with that style in Xcode. To set the text and images of the cell, use the
If you want to go beyond the predefined styles, you can add subviews to the
contentView property of the cell. When adding subviews, you are responsible for positioning those views and setting their content yourself.
Whether you use a predefined or custom cell, you can change the cell’s background using the
backgroundView property or by changing the inherited
backgroundColor property. In iOS 7, cells have a white background by default; in earlier versions of iOS, cells inherit the background color of the enclosing table view. If you want to change the background color of a cell, do so in the
tableView(_:willDisplay:forRowAt:) method of your table view delegate.