objective-c - 在 Swift 中实现 avatarImageWithUserInitials

标签 objective-c swift jsqmessagesviewcontroller

我需要从 JSQMessages 框架实现 avatarImageWithUserInitials 。然而它似乎只在 Objective-C 中实现

文档位于:http://cocoadocs.org/docsets/JSQMessagesViewController/7.3.3/Classes/JSQMessagesAvatarImageFactory.html#//api/name/avatarImageWithUserInitials:backgroundColor:textColor:font:diameter :

目前看来还没有办法在 swift 中快速实现这个功能。

如何将此功能添加到我的 swift 应用程序中?

最佳答案

您可以在此处查看完整的实现。 https://github.com/jessesquires/JSQMessagesViewController/pull/1606

它将很快成为 Swift 示例项目的一部分。

但是基本的要点是你需要制作一个头像对象,可以像这样完成。

let AvatarLeonard = JSQMessagesAvatarImageFactory.avatarImageWithUserInitials("DL", backgroundColor: UIColor.jsq_messageBubbleGreenColor(), textColor: UIColor.whiteColor(), font: UIFont.systemFontOfSize(12), diameter: UInt(kJSQMessagesCollectionViewAvatarSizeDefault))

还有这个选项:

// Create avatar with Placeholder Image
 let AvatarJobs = JSQMessagesAvatarImageFactory.avatarImageWithPlaceholder(UIImage(named: "Jobs"), diameter: UInt(kJSQMessagesCollectionViewAvatarSizeDefault))

抱歉,这花了这么长时间。 🖖🏽

关于objective-c - 在 Swift 中实现 avatarImageWithUserInitials,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37957021/

相关文章:

objective-c - 如何在同一个项目中有 2 个同名的 Objective-C 类?

ios - Objective-C block : How to set an object to nil which uses block-based callback mechanism?

arrays - Swift:将可选数组存储到 NSUserDefaults?

ios - 'JSQSystemSoundPlayer' 没有可见的@interface 声明选择器 'playSoundWithFilename:fileExtension:'

ios - JSQMessages 显示测试消息的问题

swift - "Cannot call value of non-function type"

ios - 如何打开从一个 UIWebView 到另一个 UIWebView 的链接?

ios - CGContextClearRect 导致背景颜色为黑色

ios - iOS8-iOS9设置提醒/闹钟

swift - Set 如何解决哈希冲突?