The 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.
UITableViewCell类定义了出现在UITabView对象中的cell的属性和行为。这个类包括用来设置和管理cell内容和背景(包括文本,图像和自定义视图)的属性和方法,管理cell的选择和强调状态,管理副视图和初始化编辑cell内容。
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 initWithStyle:reuseIdentifier:
method or configure the cell with that style in Xcode. To set the text and images of the cell, use the textLabel
, detailTextLabel
, and imageView
properties.
当创建cell的时候,你可以自己自定义它们或者使用几个预定义的样式之一。预定义的cell样式是最简单的选择。使用预定义样式,cell提供了位置和样式固定的标签和图像副视图。你所需要做的仅仅是把标签的文本和图像的图片方到那些固定视图中去。用initWithStyle:reuseIdentifier:方法来初始化cell或者在Xcode中来用那种样式来配置cell来使用预定义样式。是用textLabel,detailTextLabel,和imageView属性来设置cell的文字和图像。
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.
如果你想要使用预定义样式之外的样式,你可以给cell的contentView属性增加副视图。当增加了副视图,你必须给那些视图设置位置和设置它们的内容。
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:willDisplayCell:forRowAtIndexPath:
method of your table view delegate.
不管你使用预定义样式还是自定义样式,你都可以用backgroundVIew属性来改变cell的背景,或者改变继承来的属性backgroundColor。在iOS7 中,cell默认为白色;在更早的iOS 版本中,cell继承了包含它的table view的颜色。如果你想要改变cell的本经颜色,对table view的delegate使用tableView:willDisplayCell:forRowAtIndexPath:方法。
For more information about creating cells, see A Closer Look at Table View Cells in Table View Programming Guide for iOS.