简体   繁体   English

我可以使用 messageKIt 在 swift 5 ios 中创建像这样的自定义单元格吗?

[英]Can I create custom cells like these in swift 5 ios using messageKIt?

在此处输入图像描述

I am building a chat app and I am new to ios, I want to build custom cells like these using messageKIT, can anybody help me with any resource or code?我正在构建一个聊天应用程序,并且我是 ios 的新手,我想使用 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 中设计单元格。 Any UICollectionViewCell can be returned for custom cells which means any of the styling you provide from the MessageDisplayDelegate will not affect your custom cell, even if you subclass your cell from MessageContentCell .可以为自定义单元格返回任何UICollectionViewCell ,这意味着您从MessageDisplayDelegate提供的任何样式都不会影响您的自定义单元格,即使您从MessageContentCell子类化您的单元格也是如此。

Creating a custom cell involves four parts:创建自定义单元格涉及四个部分:

  1. Build a cell in Interface Builder or code that inherits from UICollectionViewCell在 Interface Builder 中构建一个单元格或从UICollectionViewCell继承的代码
  2. Set the size of your cell.设置单元格的大小。 Subclass MessageSizeCalculator if you want your cell to have the default MessageKit layout design.如果您希望您的单元格具有默认的 MessageKit 布局设计,则子类MessageSizeCalculator Subclass CellSizeCalculator 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 the messagesCollectionView .此 class 的实现将允许您的自定义单元格在messagesCollectionView中自动调整大小。
  3. 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 步中的自定义消息大小计算器。
  4. Register your custom cell and reference your custom collection view flow layout.注册您的自定义单元格并引用您的自定义集合视图流布局。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM