背景不會橫向填滿整個螢屏。我怎樣才能讓它一直伸展?
這是我的代碼:
import SwiftUI
struct ContentView: View {
@Environment(\.verticalSizeClass) var verticalSizeClass
var body: some View {
VStack(spacing: 20) {
VStack {
Text("Instant Developer")
.font(.system(.largeTitle))
.fontWeight(.bold)
.foregroundColor(.white)
Text("Get help from expert in 15 minutes")
.foregroundColor(.white)
}
HStack(alignment: .bottom, spacing: 20) {
Image("student")
.resizable()
.scaledToFit()
Image("tutor")
.resizable()
.scaledToFit()
}
.padding(.horizontal, 50)
Text("Need help with coding problem? Register!")
.foregroundColor(.white)
Spacer()
if verticalSizeClass == .compact {
HSignUpButtonGroup()
} else {
VSignUpButtonGroup()
}
}
.padding(.top, 30)
.background(Color.black)
}
}
uj5u.com熱心網友回復:
問題似乎是因為scaledToFit,它試圖保持影像的縱橫比,因此不會使背景一直延伸。
要解決此問題,只需使用.frame(maxWidth: .infinity). 確保將此修飾符放在之前background,以便顏色尊重新布局。
.padding(.top, 30)
.frame(maxWidth: .infinity) /// here!
.background(Color.black)
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/418740.html
標籤:
