问题
Is there a way to change the delete button title when editing a List?
Example -
struct ContentView: View {
@State private var users = ["Paul", "Taylor", "Adele"]
var body: some View {
NavigationView {
List {
ForEach(users, id: \.self) { user in
Text(user)
}.onDelete(perform: delete)
}.navigationBarItems(trailing: EditButton())
}
}
func delete(source: IndexSet) { }
}
回答1:
As of Xcode 11.3.1, SwiftUI doesn't support custom swipe actions for List items. Based on the history of Apple’s SDK evolution, we’re not likely to see support until the next major SDK version (at WWDC 2020) or later.
You would probably be better off implementing a different user interface, like adding a toggle button as a subview of your list item, or adding a context menu to your list item.
Note that you must be on beta 4 or later to use the contextMenu modifier on iOS.
See this - SwiftUI - Custom Swipe Actions In List
来源:https://stackoverflow.com/questions/59812931/swiftui-list-editing-mode-how-to-change-delete-button-title