简体   繁体   English

Swift IOS 应用程序中的 UI 元素彼此之间没有任何距离

[英]Swift UI elements in IOS app not getting any closer to each other

In my Swift UI app, there are these large spacings between elements in the app and I can't seem to get them to be closer after the newest X-code release.在我的 Swift UI 应用程序中,应用程序中的元素之间有很大的间距,在最新的 X 代码发布后我似乎无法让它们更接近。

Here is what the broken look is...这是破碎的样子......

Here is what it looked like before...这是它之前的样子……

Here is the code for the first 4 buttons:这是前 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)

Put

VStack(spacing:0)

Under the main VStack.在主 VStack 下。 It will solve the issue.它将解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在TableView的每一行中添加按钮,图像和其他UI元素? (iOS,快速) - How to add buttons, images and other UI elements in each row of TableView? (iOS,Swift) 没有任何UI的iOS应用 - IOS app without any UI UIImages或UIViews在iOS Swift中不会相互碰撞吗? - UIImages or UIViews are not colliding each other in iOS Swift? 在iOS应用中,如何让2个元素彼此相邻? - in an iOS app, how can I get 2 elements to sit next to each other? 为时间表应用程序设计UI(iOS Swift) - Designing UI for schedule app (ios Swift) 有没有办法在移动应用程序的一半屏幕上显示 Unity 游戏,或者在 iOS 应用程序中将 Swift UI 元素放在 Unity 游戏之上? - Is there a way to display a Unity game in half of the screen on a mobile app or to put Swift UI elements on top of a Unity game in an iOS app? 将StackView中的项目在水平轴上彼此对齐 - Align items in stackview closer to each other in horizontal axis 如何将两个 UI 元素约束到同一个地方 - Swift iOS - How to Constraint Two UI Elements to same place - Swift iOS 你如何在 Swift/iOS 的 UI 测试中迭代元素? - how do you iterate through elements in UI testing in Swift/iOS? Xcode中的UI元素似乎相互重叠。 如何解决这个问题? - UI elements in Xcode seem to be overlapping with each other. How to fix this?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM