我放弃。我想在某些视图周围进行文字环绕,但找不到任何方法。
示例代码:
struct ListView: View {
// actual text from @ObservedObject
var exText = "The statue of Laocoön and His Sons, also called the Laocoön 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ön and his sons Antiphantes and Thymbraeus being attacked by sea serpents.[1]"
@State var thumbnail:UIImage = UIImage()
var body: some View {
HStack {
Image(uiImage: thumbnail)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 70.0, height: 70.0)
.background(Color.gray)
//.onReceive() to update the image from the @ObservedObject
Text(exText)
.lineLimit(nil)
}
}
}
如果我使用text(UIImage())
插入图像,它将显示图像的底部与文本的第一行。另外,此方法不允许我自定义UIImage视图。
所有方法.mask
,.clipShape
,.compositingGroup
和.contentShape
都不起作用,因为它们只是剪切文本并且不让文本环绕其他视图。使用UIKit,这可以通过使用exclusionPaths
来实现,在SwiftUI中是否与此等效?
我在Google文档中搜索了几个小时,发现的唯一问题是here,这个问题也没有得到回答。迅捷的众神请回答我的祈祷!
答案 0 :(得分:0)
您可以使用“+”运算符。把图片放在里面:Text(Image(…))
。
Text("here is the star:") + Text(Image(systemName:"star")) + Text(", very easy.")