Reputation: 373
I am using Toolbar edit button to make the list edit, Below is the code I am using, I want to change the text color of EditButton(), there is no straight forward approach I found, Kindly help
List {
ForEach(viewModel.datas) { data in
Text(data)
}
.onDelete { offset in
self.indexSetToDelete = offset
}
}
.toolbar {
EditButton()
// I want to set the edit button color
}
Upvotes: 2
Views: 1514
Reputation: 289
It is not possible to use accentColor if you Edit button in List, you have to set a navigation trail button and need to use environment editmode
@State private var editMode: EditMode = .inactive
var body: some View {
List {
ForEach(viewModel.datas) { data in
Text(data)
}
.onDelete { offset in
self.indexSetToDelete = offset
}
}.environment(\.editMode, $editMode)
.navigationBarItems(trailing: editButton) }
private var editButton: some View {
return Button {
if editMode == .inactive {
editMode = .active
} else {
editMode = .inactive
}
} label: {
Text(editMode == .inactive ? "Edit" : "Done")
.body(color: Color.red)
}
}
Upvotes: 4
Reputation: 1088
Use func .accentColor(Color)
EditButton()
.accentColor(.red)
Upvotes: -1