簡體   English   中英

刪除 SwiftUI 表格填充

[英]Remove SwiftUI Form padding

當您使用 SwiftUI Form時,它會在前緣創建填充,這對於Form輸入來說很好,但我想向表單添加其他內容,例如占據整個屏幕寬度的圖像,但因為圖像在Form , padding 被應用並且圖像被稍微推離屏幕。 如何刪除所有Form填充?

struct MyForm: View {
  var body: some View {
    Form {
      Image(uiImage: someImage)
        .resizable()
        .aspectRatio(contentMode: .fill)
        .frame(width: UIScreen.main.bounds.width)

      TextField("Name", text: $name)

      // Other fields
    }
  }
}

我知道Form的底層視圖是UITableView ,我可以在其中執行UITableView.appearance().backgroundColor =.clear的操作來更改Form外觀,但我不知道如何刪除前導填充。

我也知道我可以將Image視圖移到Form之外並將所有內容放在堆棧中,但這會產生我想避免的其他滾動問題。

這是一個解決方案。 使用 Xcode 11.4 / iOS 13.4 測試

  Image(uiImage: someImage)
    .resizable()
    .aspectRatio(contentMode: .fill)
    .listRowInsets(EdgeInsets())        // << this one !!

注意:不需要對UIScreen.main.bounds.width進行硬編碼

暫無
暫無

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

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