在 SwiftUI 中的某些视图周围环绕文本

Sal*_*ini 8 ios swift swiftui

我放弃。我想让文本环绕某个视图,但我找不到任何方法来做到这一点。

\n

在此输入图像描述

\n

示例代码:

\n
struct ListView: View {\n    // actual text from @ObservedObject \n    var exText = "The statue of Laoco\xc3\xb6n and His Sons, also called the Laoco\xc3\xb6n Group (Italian: Gruppo del Laocoonte), has been one of the most famous ancient sculptures ever since it was excavated in Rome in 1506 and placed on public display in the Vatican,[2] where it remains. It is very likely the same statue praised in the highest terms by the main Roman writer on art, Pliny the Elder.[3] The figures are near life-size and the group is a little over 2 m (6 ft 7 in) in height, showing the Trojan priest Laoco\xc3\xb6n and his sons Antiphantes and Thymbraeus being attacked by sea serpents.[1]"\n    \n    @State var thumbnail:UIImage = UIImage()\n    \n    var body: some View {\n        HStack {\n            Image(uiImage: thumbnail)\n                .resizable()\n                .aspectRatio(contentMode: .fit)\n                .frame(width: 70.0, height: 70.0)\n                .background(Color.gray)\n                //.onReceive() to update the image from the @ObservedObject \n            Text(exText)\n                .lineLimit(nil)\n        }\n    }\n}\n
Run Code Online (Sandbox Code Playgroud)\n

如果我用来text(UIImage())插入图像,它会显示图像的底部与文本的第一行一致。另外,此方法不允许我自定义 UIImage 视图。\n所有方法.mask.clipShape和根本不起作用,因为它们只是剪切文本并且不让它环绕其他视图.compositingGroup.contentShape对于 UIKit 来说,这可以通过使用 来实现exclusionPaths,SwiftUI 中是否有等效的方法?

\n

我用谷歌搜索并搜索了几个小时的文档,我所能找到的就是这个问题但也没有得到解答。各位神灵快来回应我的祈祷吧!

\n

小智 1

您可以使用“+”运算符。将图像放入:Text(Image(\xe2\x80\xa6))

\n
Text("here is the star:") + Text(Image(systemName:"star")) + Text(", very easy.")\n
Run Code Online (Sandbox Code Playgroud)\n