这是我的目标布局。
import SwiftUI
import PlaygroundSupport
struct TestView: View {
let text: String
var body: some View {
Text(self.text)
}
}
struct ContentView: View {
var body: some View {
ZStack {
TestView(text: "bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla")
.frame(width: 250)
.background(Color.red)
}
}
}
PlaygroundPage.current.setLiveView(ContentView())
但我也想使用GeometryReader
and 当我把它放在Text
里面时GeometryReader
它会占据整个高度。
import SwiftUI
import PlaygroundSupport
struct TestView: View {
let text: String
var body: some View {
GeometryReader { reader in
Text(self.text)
}
}
}
struct ContentView: View {
var body: some View {
ZStack {
TestView(text: "bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla")
.frame(width: 250)
.background(Color.red)
}
}
}
PlaygroundPage.current.setLiveView(ContentView())
我怎样才能解决这个问题?