如何在swiftui的屏幕顶部移动vstack? [英] How to move vstack at top of the screen in swiftui?
问题描述
如何在 swiftUI 中移动此堆栈顶部的屏幕.在我的代码下面.[1]:https://i.stack.imgur.com/wBD2c.png
how to move this stack top of the screen in swiftUI. below my code there. [1]: https://i.stack.imgur.com/wBD2c.png
推荐答案
您可以移除 HStack
并将 Spacer() 放在您的 VStack
中,这将强制视图到顶部.
You can remove the HStack
and place the Spacer() within your VStack
which will force the view to the top.
var body: some View {
VStack {
Text("Hello World")
Text("Test")
Spacer()
}
}
或者如果你想将视图保持在屏幕的左侧,你可以使用另一个 VStack 和 Spacer()
Or if you want to keep the View to the left of the screen you can use another VStack and Spacer()
var body: some View {
VStack {
HStack {
VStack {
Text("Hello World")
Text("Test")
Spacer()
}
Spacer()
}
}
}
如果您刚刚开始使用 SwiftUI,我强烈推荐 Paul Hudson 的 100 天的 SwiftUI.它是免费的,并且会教你很多关于 SwiftUI 的知识.
If you are just getting started with SwiftUI I highly recommend Paul Hudson's 100 Days of SwiftUI. It's free and will teach you a lot about SwiftUI.
这篇关于如何在swiftui的屏幕顶部移动vstack?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!