我是 swiftui 的新手,正在为一些基本的东西苦苦挣扎 我正在尝试创建一个在按钮上有 2 个按钮的 View 。 我想要一张图片作为整个 View 的背景。
var body: some View {
ZStack {
Image("bg-welcome").edgesIgnoringSafeArea(.all)
}
}
这很好用 我这样设置 View
NavigationView {
ZStack {
VStack(alignment: HorizontalAlignment.leading, spacing: 10) {
Text("1").foregroundColor(.white)
Text("2").foregroundColor(.white)
Spacer()
Button(action: {}){
Text("ooooooooo")
}
}.background(Image("bg-welcome"))
}
}
现在我有两个问题: - 在背景图像之前显示一个空白 - 第一个文本被推到下面,肯定是在为导航栏保留的空间之后,我不想要它,因为当我导航到下一个屏幕时,空间仍然被占用,我想要整个可用屏幕
谢谢你的帮助
最佳答案
试试这个:
var body: some View {
NavigationView {
ZStack {
VStack(alignment: HorizontalAlignment.leading, spacing: 10) {
Text("1").foregroundColor(.white)
Text("2").foregroundColor(.white)
Spacer()
Button(action: {}){
Text("Button 1")
}
Button(action: {}){
Text("Button 2")
}
}.background(Image("remachine_poster")
.resizable()
.aspectRatio(contentMode: .fill)).edgesIgnoringSafeArea(.all)
}
}
}
关于ios - 使用全屏图像和导航查看链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58787967/