【问题标题】:Typing attributed text with imags in UITextView在 UITextView 中键入带有图像的属性文本
【发布时间】:2020-02-24 23:36:12
【问题描述】:

我正在开发无法满足此要求的聊天应用程序。 我需要输入带有自定义图像(表情符号)的文本作为输入,但不知道该怎么做。

我通过互联网进行了一些研发,但没有帮助实施。 请有人提供sn-p如何实现。

提前致谢。

【问题讨论】:

  • 嗨!请发布您的代码,以便我们帮助解决特定问题。

标签: ios swift xmpp uitextview chat


【解决方案1】:

试试这个:

// create an NSMutableAttributedString that we'll append everything to
let fullString = NSMutableAttributedString(string: "Start of text")

// create our NSTextAttachment
let image1Attachment = NSTextAttachment()
image1Attachment.image = UIImage(named: "awesomeIcon.png")

// wrap the attachment in its own attributed string so we can append it
let image1String = NSAttributedString(attachment: image1Attachment)

// add the NSTextAttachment wrapper to our full string, then add some more text.
fullString.append(image1String)
fullString.append(NSAttributedString(string: "End of text"))

// draw the result in a label
yourLabel.attributedText = fullString

【讨论】:

    猜你喜欢
    • 2023-03-17
    • 1970-01-01
    • 2013-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多