[英]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.