gpt4 book ai didi

ios - VStack 的帧大小没有填满整个屏幕

转载 作者:行者123 更新时间:2023-11-28 07:23:04 28 4
gpt4 key购买 nike

我在使用 SwiftUI 创建一些 View 时遇到了 VStack 框架尺寸的奇怪错误。渐变不会填满屏幕的所有高度。那只是 Xcode 错误还是我做错了什么? enter image description here

struct WelcomeView : View {

private let colors = [
Color(red: 29/255, green: 151/255, blue: 108/255),
Color(red: 147/255, green: 249/255, blue: 185/255)
]

let screenSize = UIScreen.main.bounds

var body: some View {
VStack {
Text("Content here")
}
.frame(width: screenSize.width, height: screenSize.height)
.background(LinearGradient(gradient: Gradient(colors: colors),
startPoint: .bottom, endPoint: .top), cornerRadius: 0)

}
}

最佳答案

var body: some View {
VStack {
Spacer()
Text("Content here")
Spacer()
}
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity)
.background(LinearGradient(gradient: Gradient(colors: colors), startPoint: .bottom, endPoint: .top), cornerRadius: 0)
.edgesIgnoringSafeArea(.all)

}

来源:https://www.hackingwithswift.com/quick-start/swiftui/how-to-place-content-outside-the-safe-area

关于ios - VStack 的帧大小没有填满整个屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57480619/

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