2

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
        }
Rama Krish
  • 373
  • 1
  • 13

2 Answers2

3

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)
    }
}
Ram
  • 269
  • 2
  • 9
-1

Use func .accentColor(Color)

EditButton()
  .accentColor(.red)
cluelessCoder
  • 948
  • 6
  • 19