Reputation: 7636
I have to fill that background of a Section with a certain color like this
By now I tried
NavigationView {
Form {
Section {
Text("Error message!")
}.background(Color.red.opacity(0.2))
Section {
Text("Label 1")
}
Section {
Text("Label 2")
}
}.navigationBarTitle("title", displayMode: NavigationBarItem.TitleDisplayMode.inline)
}
but, there seem to be a predefined padding, so I can't fill the margins
Upvotes: 4
Views: 6380
Reputation: 2762
Add .listRowBackground(Color.red.opacity(0.2))
to your section
NavigationView {
Form {
Section {
Text("Error message!")
}.listRowBackground(Color.red.opacity(0.2))
Section {
Text("Label 1")
}
Section {
Text("Label 2")
}
}.navigationBarTitle("title", displayMode: NavigationBarItem.TitleDisplayMode.inline)
}
and if you want to clear the background of a section use:
.listRowBackground(Color.clear)
if you want to make the list transparent add the above to sections and add this to your list:
.scrollContentBackground(.hidden)
on the list
Upvotes: 2
Reputation: 489
Maybe this will help, at least in Simulator this seems to be a solution to your request:
NavigationView {
Form {
Section {
HStack {
Text("Error message!")
Spacer()
}
.padding(.vertical)
.listRowInsets(EdgeInsets())
}
.padding(.horizontal)
.background(Color.red.opacity(0.2))
Section {
Text("Label 1")
}
Section {
Text("Label 2")
}
}
.navigationBarTitle("title", displayMode: .inline)
}
Upvotes: 5