首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UICollectionViewListCell配件TopTrailing定位

UICollectionViewListCell配件TopTrailing定位
EN

Stack Overflow用户
提问于 2021-04-30 19:42:08
回答 1查看 364关注 0票数 0

iOS 14为UICollectionView引入了一系列的进步,包括新的UICollectionViewListCell。使用defaultContentConfiguration,可以向单元格中添加附件视图。我希望重新创建一个iMessage会话行(邮件也关闭),其中日期标签在顶部尾随角。是否可以使用默认配置来完成此操作?为此,必须创建一个自定义单元似乎有点过分。

这是我目前所拥有的。

代码语言:javascript
复制
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
}

这是我想要的结果

这是另一个例子的邮件

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-05-06 19:44:40

默认的UICollectionViewListCell具有有限的自定义可能性。

最好的方法是使用自定义的UICollectionViewCell子类。相反,您将让单元格注册注册您的自定义类,并按照您对内置UICollectionViewListCell类对象的排队列方式将单元格排出队列。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67339605

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档