【问题标题】:How do you remove the margin from the top of the screen to a form?如何将屏幕顶部的边距删除到表单?
【发布时间】:2022-11-01 22:08:05
【问题描述】:

我在屏幕顶部和我的文本输入框之间有这个空间。我怎样才能减少这个空间?我不想把输入框抬得太高,因为它会被凹槽挡住。但是,我想把它提出来,这样它在我的应用程序中看起来并不奇怪。

另外,我怎样才能删除按钮后面的白色背景,使它只是蓝色而不是它后面的白色矩形?

这是一个屏幕截图:

这是代码:

import SwiftUI

struct ContentView: View {
    @State var TextPlaceholder = ""
        
    var body: some View {
        
        GeometryReader { geo in
            NavigationView{
                VStack{
                    Form {
                        Section{
                            TextField("Placeholder", text: $TextPlaceholder)
                                .multilineTextAlignment(TextAlignment.center)
                                .frame(
                                    height: geo.size.height*0.65,
                                    alignment: .center
                                )
                        }
                    }
                    Section{
                        Button(action: {}) {
                            SwiftUI.Text("Submit")
                                .frame(width: 250, height: 50, alignment: .center)
                                .background(Color.blue)
                                .foregroundColor(.white)
                                .cornerRadius(8)
                        }.padding()
                    }
                    
                }
                //.navigationTitle("Summarizer")
            }//.edgesIgnoringSafeArea(.all)
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
            .preferredColorScheme(.light)
            .previewInterfaceOrientation(.portraitUpsideDown)
    }
}

【问题讨论】:

  • 刚刚检查,在上面的 iPhone X 布局上看起来不错。除了您的其他要求按钮背景。
  • @LawrenceGimenez 我刚刚在 iPhone 12 Pro 上试用过 - 空间仍然存在同样的问题。

标签: ios swift swiftui swiftui-navigationview swiftui-form


【解决方案1】:

好的,所以要回答这个包含在导航视图中的任何内容,除了标题文本,因此空间很大 - 通过删除导航视图,空间被删除。希望这可以帮助任何对此也摸不着头脑的人!

【讨论】:

    猜你喜欢
    • 2019-04-18
    • 1970-01-01
    • 2014-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多