UIListContentConfiguration
UIListContentConfiguration 表示列表里一行的内容:主文字、副文字、左边的图片。
它只是一份数据。写给单元格的 contentConfiguration 之后才显示出来,而且单元格存下的是副本:
js
/** @param {UICollectionViewListCell} cell */
function fill(cell) {
const content = cell.defaultContentConfiguration();
content.text = '第一次';
cell.contentConfiguration = content;
content.text = '第二次';
}效果:对一个单元格调 fill(cell),单元格显示「第一次」。写给单元格之后改的是 App 手里的那一份,单元格里的副本不变。要让它显示「第二次」,再赋值一次。读 cell.contentConfiguration 得到的也是副本,改它同样不影响单元格。
继承关系:EventTarget → NSObject → UIListContentConfiguration
构造函数
不能用 new 创建,new UIListContentConfiguration() 抛 TypeError。从单元格的 defaultContentConfiguration() 拿,或者用下面三个静态方法。
静态方法
UIListContentConfiguration.cellConfiguration()
一行主文字的样式。
UIListContentConfiguration.subtitleCellConfiguration()
主文字下面一行副文字的样式。
UIListContentConfiguration.valueCellConfiguration()
主文字在左、副文字在右的样式。
三种样式在屏幕上的样子未在模拟器验证,含义来自 Apple 的文档。
实例属性
| 属性 | 说明 |
|---|---|
text | 主文字 |
secondaryText | 副文字 |
image | 文字左边的图片 |
对应的 iOS API
| ObjC | JS |
|---|---|
[UIListContentConfiguration cellConfiguration] | UIListContentConfiguration.cellConfiguration() |
content.text = @"x" | content.text = 'x' |
content.image = image | content.image = image |