簡體   English   中英

如何在 SwiftUI 中的表單底部添加空格?

[英]How to add blank space at the bottom of a form in SwiftUI?

我在 SwiftUI 中有一個用於添加記錄的模式表。 模態表使用具有多個 TextField 元素的表單。 現在我想用與表單背景(灰色)相同的顏色在表單的末尾添加一些空間。

將 padding() 添加到最后一個 TextField 會導致所有 TextField 都具有填充。 然后我嘗試添加一個 Text("").hidden().padding(.bottom, 500) 作為最后一個表單元素,但該空間隨后被白色背景色填充。

更新:如果您在 Form 視圖中放置一個帶內邊距的墊片,您會得到以下結果(背景為紅色以進行演示):

在此處輸入圖片說明

這是代碼:

import SwiftUI

struct ContentView: View {
    var body: some View {
        HStack {
            Text("Hello, World!")
        }
        .sheet(isPresented: .constant(true), content: { SheetView() }
        )
    }
}

struct SheetView: View {
    var body: some View {
        Form {
            TextField("Demo Field", text: .constant("KK"))
            Spacer()
                .padding(.bottom, 500)
                .background(Color(.red))
        }
    }
}

我正在尋找的內容與 Apple 的通訊錄應用程序中的內容相同。 如果您轉到“新聯系人”並向下滾動到表單末尾,則會有相當多的空間:

在此處輸入圖片說明

為此,您必須使用一個section

struct SheetView: View {
    var body: some View {
        Form {
            Section(header: Text("")) {
                TextField("Demo Field", text: .constant("KK"))
            }
            Section(header: Text("")) {
                EmptyView()

            }
            .padding(.bottom, 200)
            Section(header: Text("")) {
                TextField("Demo Field", text: .constant("KK"))
            }
        }
    }
}

結果:

在此處輸入圖片說明

考慮添加一個Spacer()如下:

Spacer()
  .padding(.bottom, 500)
  .background(gray)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM