UITableViewCell的层级结构

1,220 阅读1分钟

UITableViewCell中的contentView、backgroundView、selectedBackgroundView、multipleSelectionBackgroundView

UITableViewCell 层级结构

  1. UITableViewCell
 Default is nil for cells in UITableViewStylePlain, and non-nil for UITableViewStyleGrouped. 
 The 'backgroundView' will be added as a subview behind all other views.
  1. backgroundView
Default is nil for cells in UITableViewStylePlain, and non-nil for UITableViewStyleGrouped. 
The 'selectedBackgroundView' will be added as a subview directly above the backgroundView if not nil, or behind all other views. 
It is added as a subview only when the cell is selected. 
Calling -setSelected:animated: will cause the 'selectedBackgroundView' to animate in and out with an alpha fade.
  1. selectedBackgroundView (multipleSelectionBackgroundView)]
If you want to customize cells by simply adding additional views, 
you should add them to the content view so they will be positioned appropriately as the cell transitions into and out of editing mode.
  1. contentView
selectedBackgroundView只有在用户点击cell的时候才会被cell当作子类加入,层级在backgroundView(如果它存在)之上,其他所有控件之下。

multipleSelectionBackgroundView的层级是在contentView之下,selectedBackgroundView之上。

相关文章