SwiftUI - List editing mode - how to change delete button title?

余生长醉 提交于 2020-12-13 02:58:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!