【问题标题】:Remove SwiftUI Form padding删除 SwiftUI 表单填充
【发布时间】:2020-10-11 11:18:37
【问题描述】:

当您使用 SwiftUI Form 时,它会在前沿创建填充,这对于 Form 输入很好,但我想向表单添加其他内容,例如占据整个屏幕宽度的图像,但由于图像位于Form 中,因此应用了填充并且图像被稍微推离屏幕。如何删除所有 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 之外并将所有内容放入堆栈中,但这会产生我想避免的其他滚动问题。

【问题讨论】:

    标签: ios swift uikit swiftui


    【解决方案1】:

    这里有一个解决方案。使用 Xcode 11.4 / iOS 13.4 测试

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

    注意:不需要硬编码到UIScreen.main.bounds.width

    【讨论】:

    • 啊,谢谢!我将 listRowInsets 修饰符放在表单上而不是子视图上
    猜你喜欢
    • 2020-06-28
    • 1970-01-01
    • 1970-01-01
    • 2021-09-06
    • 2019-10-30
    • 2020-08-21
    • 2021-03-19
    • 1970-01-01
    相关资源
    最近更新 更多