iOS 14为UICollectionView引入了一系列的进步,包括新的UICollectionViewListCell。使用defaultContentConfiguration,可以向单元格中添加附件视图。我希望重新创建一个iMessage会话行(邮件也关闭),其中日期标签在顶部尾随角。是否可以使用默认配置来完成此操作?为此,必须创建一个自定义单元似乎有点过分。
这是我目前所拥有的。
let cellRegistration = UICollectionView.CellRegistration<UICollectionViewListCell, Int> { cell, indexPath, item in
var content = cell.defaultContentConfiguration()
content.text = "Title"
content.secondaryText = "This is the body of the message and it's really long. I want to see where it finally truncates because thats what it should do eventually you know?"
content.secondaryTextProperties.numberOfLines = 2
content.image = UIImage(systemName: "star")
let label = UILabel()
label.text = "4/26/7"
label.textColor = .secondaryLabel
label.font = .preferredFont(forTextStyle: .caption1)
let customAccessory = UICellAccessory.CustomViewConfiguration(
customView: label,
placement: .trailing(displayed: .always))
cell.accessories = [.customView(configuration: customAccessory)]
cell.contentConfiguration = content
cell.tintColor = .tertiaryLabel
}

这是我想要的结果

这是另一个例子的邮件

发布于 2021-05-06 19:44:40
默认的UICollectionViewListCell具有有限的自定义可能性。
最好的方法是使用自定义的UICollectionViewCell子类。相反,您将让单元格注册注册您的自定义类,并按照您对内置UICollectionViewListCell类对象的排队列方式将单元格排出队列。
https://stackoverflow.com/questions/67339605
复制相似问题