Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios NSTextAttachment()附加属性_Ios_Swift_Uitextview - Fatal编程技术网

Ios NSTextAttachment()附加属性

Ios NSTextAttachment()附加属性,ios,swift,uitextview,Ios,Swift,Uitextview,我想在添加到我的UITextView的一些图像上添加额外的信息。该类是NSTextAttachment()。我需要我的图像有一些字符串描述,以便应用程序知道图像中的内容。如何添加此额外功能?是否通过分机 let attachment = NSTextAttachment() attachment.image = image attachment.bounds = CGRect(origin: .zero, size: image.size) // Extra properties wanted

我想在添加到我的
UITextView
的一些图像上添加额外的信息。该类是
NSTextAttachment()
。我需要我的图像有一些
字符串
描述,以便应用程序知道图像中的内容。如何添加此额外功能?是否通过
分机

let attachment = NSTextAttachment()
attachment.image = image
attachment.bounds = CGRect(origin: .zero, size: image.size)
// Extra properties wanted
attachment.description = "add in info about what is in attachment"
attachment.moreInfo = "some more info about the attachment"
已经有一段时间了,但我的解决方案已经出来了。 扩展
NSTextAttachment
您可以使用
objc\u getAssociatedObject
objc\u setAssociatedObject

使用它时,请使用
EmojiTextAttachment
而不是
NSTextAttachment

  let emoticon:EmojiTextAttachment = EmojiTextAttachment()
                    let image = UIImage(named: myImage) as UIImage!
                    emoticon.image = image?.resizeSelf(newWidth, newHeight)
                    emoticon.emoticonName = emoname

objc\u getAssociatedObject

的文档通过属性字符串本身的自定义属性,而不是通过文本附件添加您的信息。@matt您能给我举个例子吗?我一直在努力,真的不知道如何做到这一点…我不知道你的意思。您只能使用NSTextAttachment,因为您有一个NSMutableAttributeString。好的,让您添加属性到属性字符串的任何延伸。没有法律规定必须使用布局引擎知道的属性。您可以有一个
description
属性和一个
moreInfo
属性,并给它们任何您喜欢的值。现在,您已经将自定义信息存储在字符串中所需的位置。我需要这些属性,以便以后可以调用它们。例如,图像1的描述是什么。我不明白你是怎么说的?我无法将扩展名添加到实际附件,只能将信息添加到范围?你是这么说的吗?
  let emoticon:EmojiTextAttachment = EmojiTextAttachment()
                    let image = UIImage(named: myImage) as UIImage!
                    emoticon.image = image?.resizeSelf(newWidth, newHeight)
                    emoticon.emoticonName = emoname