Swift UI 个元素在 IOS 应用中彼此之间没有任何距离
Swift UI elements in IOS app not getting any closer to each other
在我的 Swift UI 应用程序中,应用程序中的元素之间有很大的间距,在最新的 X 代码发布后我似乎无法让它们更接近。
Here is what the broken look is...
Here is what it looked like before...
前 4 个按钮的代码如下:
HStack {
Text("Toggle between colors")
.padding(.horizontal)
Spacer()
Button(action: {
colorToggleLogic()
}, label: {
Text("Color")
.frame(minWidth: 0, maxWidth: 75)
.padding(5)
.background(LinearGradient(gradient: Gradient(colors: [Color.blue, Color.gray]), startPoint: .leading, endPoint: .trailing))
.background(Color.blue)
.cornerRadius(5)
.foregroundColor(.black)
}).offset(x: -5, y: 0)
}.foregroundColor(.black)
// zero toggle button
HStack {
Text("Enable/Disable Zeros in division")
.padding(.horizontal)
Spacer()
Button(action: {
if viewModel.zeroToggle == false {
viewModel.zeroToggle = true
zeroToggleName = "Enabled"
zeroToggleColor = .green
}
else {
viewModel.zeroToggle = false
zeroToggleName = "Disabled"
zeroToggleColor = .red
}
UserDefaults.standard.set(self.viewModel.zeroToggle, forKey: "zeroToggle")
}, label: {
Text(zeroToggleName)
.frame(minWidth: 0, maxWidth: 75)
.padding(5)
.background(LinearGradient(gradient: Gradient(colors: [Color(zeroToggleColor), Color.gray]), startPoint: .leading, endPoint: .trailing))
.background(Color(zeroToggleColor))
.cornerRadius(5)
.foregroundColor(.black)
}).offset(x: -5, y: 0)
}.offset(x: 0, y: 5)
.foregroundColor(.black)
// purchase full version
HStack {
Text("Purchase full version")
.padding(.horizontal)
Spacer()
NavigationLink(destination:
ParentalGate()
) {
Text("Purchase")
.frame(minWidth: 0, maxWidth: 75)
.padding(5)
.background(LinearGradient(gradient: Gradient(colors: [Color.black, Color.gray]), startPoint: .leading, endPoint: .trailing))
.background(Color(.black))
.cornerRadius(5)
.foregroundColor(.white)
}
.offset(x: -5, y: 0)
放
VStack(spacing:0)
在主VStack下。它将解决问题。
在我的 Swift UI 应用程序中,应用程序中的元素之间有很大的间距,在最新的 X 代码发布后我似乎无法让它们更接近。
Here is what the broken look is...
Here is what it looked like before...
前 4 个按钮的代码如下:
HStack {
Text("Toggle between colors")
.padding(.horizontal)
Spacer()
Button(action: {
colorToggleLogic()
}, label: {
Text("Color")
.frame(minWidth: 0, maxWidth: 75)
.padding(5)
.background(LinearGradient(gradient: Gradient(colors: [Color.blue, Color.gray]), startPoint: .leading, endPoint: .trailing))
.background(Color.blue)
.cornerRadius(5)
.foregroundColor(.black)
}).offset(x: -5, y: 0)
}.foregroundColor(.black)
// zero toggle button
HStack {
Text("Enable/Disable Zeros in division")
.padding(.horizontal)
Spacer()
Button(action: {
if viewModel.zeroToggle == false {
viewModel.zeroToggle = true
zeroToggleName = "Enabled"
zeroToggleColor = .green
}
else {
viewModel.zeroToggle = false
zeroToggleName = "Disabled"
zeroToggleColor = .red
}
UserDefaults.standard.set(self.viewModel.zeroToggle, forKey: "zeroToggle")
}, label: {
Text(zeroToggleName)
.frame(minWidth: 0, maxWidth: 75)
.padding(5)
.background(LinearGradient(gradient: Gradient(colors: [Color(zeroToggleColor), Color.gray]), startPoint: .leading, endPoint: .trailing))
.background(Color(zeroToggleColor))
.cornerRadius(5)
.foregroundColor(.black)
}).offset(x: -5, y: 0)
}.offset(x: 0, y: 5)
.foregroundColor(.black)
// purchase full version
HStack {
Text("Purchase full version")
.padding(.horizontal)
Spacer()
NavigationLink(destination:
ParentalGate()
) {
Text("Purchase")
.frame(minWidth: 0, maxWidth: 75)
.padding(5)
.background(LinearGradient(gradient: Gradient(colors: [Color.black, Color.gray]), startPoint: .leading, endPoint: .trailing))
.background(Color(.black))
.cornerRadius(5)
.foregroundColor(.white)
}
.offset(x: -5, y: 0)
放
VStack(spacing:0)
在主VStack下。它将解决问题。