How to remove the left and right Padding of a Form in SwiftUI? Every View I create has padding in the leading and trailing.
Here is my code
init() {
UITableView.appearance().tableHeaderView = UIView(frame: CGRect(x: 0, y: 0, width: 0, height: Double.leastNonzeroMagnitude))
}
var body: some View {
NavigationView{
Form{
Section{
Picker(selection: $selectedCurrency, label: Text("Date Format"), content: {
ForEach(0 ..< self.dateStyles.count) { (index:Int) in
Text("\(self.dateStyles[index])")
}
})
}
}.listStyle(PlainListStyle())
.listRowInsets(.init(top: 0, leading: 0, bottom: 0, trailing: 0))
.navigationBarTitle(Text("Settings"), displayMode: .inline)
.onAppear(){
if ProcessInfo.processInfo.environment["XCODE_RUNNING_FOR_PREVIEWS"] != "1"{
//some code
}
}
}
}
Using something else is probably best but this removes the padding.
Form {
...
}.padding(.leading, -16)
.padding(.trailing, -16)
You should use a List
instead of a Form
, take a look at the different list styles , I think you are after .listStyle(GroupedListStyle())
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.