[英]Can I create custom cells like these in swift 5 ios using messageKIt?
Yes, what you want is definitely possible!是的,你想要的绝对是可能的!
You may refer to this GitHub repo that contains a text document/guide on how to configure customs cells with MessageKit
and examples.您可以参考此GitHub 存储库,其中包含有关如何使用MessageKit
和示例配置海关单元的文本文档/指南。
An extract from the repo:回购的摘录:
Note : If you choose to use the
.custom
kind you are responsible for all of the cell's layout.注意:如果您选择使用.custom
类型,您将负责所有单元格的布局。 You can design the cell in code or Interface Builder.您可以在代码或 Interface Builder 中设计单元格。 AnyUICollectionViewCell
can be returned for custom cells which means any of the styling you provide from theMessageDisplayDelegate
will not affect your custom cell, even if you subclass your cell fromMessageContentCell
.可以为自定义单元格返回任何UICollectionViewCell
,这意味着您从MessageDisplayDelegate
提供的任何样式都不会影响您的自定义单元格,即使您从MessageContentCell
子类化您的单元格也是如此。
Creating a custom cell involves four parts:创建自定义单元格涉及四个部分:
- Build a cell in Interface Builder or code that inherits from
UICollectionViewCell
在 Interface Builder 中构建一个单元格或从UICollectionViewCell
继承的代码- Set the size of your cell.设置单元格的大小。 Subclass
MessageSizeCalculator
if you want your cell to have the default MessageKit layout design.如果您希望您的单元格具有默认的 MessageKit 布局设计,则子类MessageSizeCalculator
。 SubclassCellSizeCalculator
if you want to further customize your own cell design.如果您想进一步自定义您自己的单元格设计,则子类CellSizeCalculator
。 The implementation of this class will allow your custom cell to automatically size itself within themessagesCollectionView
.此 class 的实现将允许您的自定义单元格在messagesCollectionView
中自动调整大小。- Add your custom cell size to the collection view flow layout.将您的自定义单元格大小添加到集合视图流布局。 Subclass
MessagesCollectionViewFlowLayout
, and use the custom message size calculator from step 2, above.子类MessagesCollectionViewFlowLayout
,并使用上面第 2 步中的自定义消息大小计算器。- Register your custom cell and reference your custom collection view flow layout.注册您的自定义单元格并引用您的自定义集合视图流布局。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.