Hello,
I have a view with a TextField, and a List below, like this:
struct ContentView: View {
var body: some View {
NavigationStack {
MainView()
}
}
}
struct ListView: View {
var body: some View {
List {
Text("Title")
}
}
}
struct MainView: View {
@State private var searchText = ""
var body: some View {
VStack {
TextField("Search", text: $searchText)
.textFieldStyle(RoundedBorderTextFieldStyle())
ListView()
}
}
}
I am trying to move the list closer up to the textfield, but I can't get it to work. I don't want to use a "plain" list, because I'd still like to have the rounded corners and the horizontal padding.
Using padding
or offset
moves the list, but with the padding of the list itself, so it blocks the textfield. I have tried setting the spacing of the VStack to 0, but it doesn't change anything, and neither does applying any of the following modifiers to the list:
.onAppear {
UITableView.appearance().contentInset.top = -35
}
.listRowInsets(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0))
.scrollContentBackground(.hidden)
.environment(\.defaultMinListHeaderHeight, 0)
Does anyone know how to do this? Thanks