gpt4 book ai didi

ios - 无法设置其中包含可调整大小的图像的 HStack

转载 作者:行者123 更新时间:2023-12-01 19:29:50 27 4
gpt4 key购买 nike

我一直在尝试制作具有 HStack 的 View 与 Image在其中,Image设置为可通过 aspectRatio 调整大小的 .fill .不知何故,它破坏了所有框架并在布局中引入了空间
enter image description here
例如,在上面的屏幕截图中,顶部有一个不必要的边距。我已经尝试手动设置 HStack Image 的帧,但即使高度正确,它们仍然从顶部偏移了一个边距。我该如何摆脱它?
正文代码:

var body: some View {
ZStack {
Color(#colorLiteral(red: 0.09019607843, green: 0.09411764706, blue: 0.1333333333, alpha: 1))
HStack {
Image("onboardingOrnament").resizable()
.aspectRatio(contentMode: .fill)
.frame(height: UIScreen.main.bounds.height)
Spacer()
VStack() {
VStack(spacing: 20) {
Text("INSTATOOL")
.font(.custom("Ubuntu-Medium", size: 28))
.foregroundColor(.white)
Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.")
.font(.custom("AvenirNextCyr-Medium", size: 14))
.foregroundColor(Color(#colorLiteral(red: 0.4823529412, green: 0.4980392157, blue: 0.6196078431, alpha: 1)))
}
.padding(.top, 100)
Spacer()
Button(action: {
self.viewController?.present(style: .fullScreen, transitionStyle: .coverVertical) {
DashboardView()
}
}) {
ZStack() {
HStack() {
Text("NEXT")
.font(.custom("AvenirNextCyr-Demi", size: 16))
.foregroundColor(Color(#colorLiteral(red: 0.1294117647, green: 0.137254902, blue: 0.1882352941, alpha: 1)))
Image("arrowOnboarding")
.resizable()
.frame(width: 14, height: 6)
.foregroundColor(Color(#colorLiteral(red: 0.1294117647, green: 0.137254902, blue: 0.1882352941, alpha: 1)))
}
}
}
.frame(width: 190, height: 50)

.background(Color(#colorLiteral(red: 1, green: 0.6745098039, blue: 0.1882352941, alpha: 1)))
.cornerRadius(10)
Spacer().frame(height: 50)
}
}
}
}

最佳答案

我假设您想扩展到安全区域之外,例如

var body: some View {
ZStack {
Color(#colorLiteral(red: 0.09019607843, green: 0.09411764706, blue: 0.1333333333, alpha: 1))
HStack {
Image("test1").resizable()
.aspectRatio(contentMode: .fill)
// .frame(height: UIScreen.main.bounds.height) // << wrong !!

// ... other content


}.edgesIgnoringSafeArea(.all) // << this one !!
}

关于ios - 无法设置其中包含可调整大小的图像的 HStack,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63582341/

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