In SwiftUI I have a simple custom toolbar with a Text:
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationStack {
VStack {
Text("Hi")
}
.toolbar {
ToolbarItem(placement: .principal) {
HStack {
Text("My Toolbar")
.border(.red)
Spacer()
}
}
}
}
}
}
When I run in portrait the text in the toolbar is shown correctly. When I rotate to landscape the text view is displaced:
However when I run the app in landscape the UI renders correctly in both orientations.
What can I do to avoid a custom toolbar (not just a single string) breaking the layout when rotating from portrait to landscape?


