在SwiftUI的`Text`中使用`NSTextAttachment`

7

SwiftUI的Text不能与NSTextAttachment一起使用吗?我有这个AttributedString

var attributedString: AttributedString {
    var sampleAttributedString = AttributedString(sampleText)
    // Apply some bold and italics attributes to sampleAttributedString
     ...
    // create NSMutableAttributedString
    let mutableAttributedString = NSMutableAttributedString(sampleAttributedString)
    let image1Attachment = NSTextAttachment()
    image1Attachment.image = UIImage(named: "audio.png")
    let imageString = NSAttributedString(attachment: image1Attachment)
    mutableAttributedString.append(imageString)
    mutableAttributedString.append(NSAttributedString(string: "End of text"))

    sampleAttributedString = AttributedString(mutableAttributedString)

    return sampleAttributedString
}

当我在SwiftUI视图中使用上述代码如下:

var body: some View {
    Text(attributedString)
}

我嵌入的图片没有显示出来。所有其他文本都按预期呈现。catch 没有被调用。图片在资源中,我也尝试过使用系统图片。
如果我将相同的属性字符串设置为 UILabelattributedText 属性,相同的逻辑就会起作用。
感谢任何帮助。
1个回答

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接