gpt4 book ai didi

swiftui - 将 View 固定到屏幕底部并忽略底部安全区域

转载 作者:行者123 更新时间:2023-12-05 02:41:25 30 4
gpt4 key购买 nike

布局问题 - 如何设置 View block 以扩展到底部安全区域?我查看了 ignoresSafeAreas() 的各种来源,但无法达到我正在寻找的结果。稍后,我希望能够向上扩展此 View ,但从短开始。如果这是有道理的话。

    var body: some View {
VStack{
Spacer()
HStack(alignment: .center) {
Text ("Expand to fill bottom safe area ...?")
.foregroundColor(.white)
}

.frame(minWidth: 100, maxWidth: .infinity, minHeight: 50, maxHeight: 100)
.background(Color.red)
.ignoresSafeArea()
}
}

enter image description here

最佳答案

选项 1

ignoresSafeArea 放在 background 中。这将使红色延伸到设备边缘,但 HStack 的位置将保持不变。

struct ContentView: View {
var body: some View {
VStack{
Spacer()

HStack(alignment: .center) {
Text ("Expand to fill bottom safe area ...?")
.foregroundColor(.white)
}

.frame(minWidth: 100, maxWidth: .infinity, minHeight: 50, maxHeight: 100)
.background(Color.red.ignoresSafeArea()) /// inside `background`
}
}
}

选项 2

ignoresSafeArea放在VStack上,一切都会忽略安全区域。

struct ContentView: View {
var body: some View {
VStack{
Spacer()

HStack(alignment: .center) {
Text ("Expand to fill bottom safe area ...?")
.foregroundColor(.white)
}

.frame(minWidth: 100, maxWidth: .infinity, minHeight: 50, maxHeight: 100)
.background(Color.red)
}
.ignoresSafeArea() /// attached to `VStack`
}
}

结果:

<表类="s-表"><头>选项 1选项 2<正文> Red color extends to bottom of screen, text stays put Text and red color stick to the bottom of the screen

关于swiftui - 将 View 固定到屏幕底部并忽略底部安全区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68138102/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com