SwiftUI-列表编辑模式-如何更改删除按钮标题? [英] SwiftUI - List editing mode - how to change delete button title?

查看:63
本文介绍了SwiftUI-列表编辑模式-如何更改删除按钮标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在编辑列表时是否可以更改删除按钮的标题?

Is there a way to change the delete button title when editing a List?

示例-


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) { }
}

推荐答案

从Xcode 11.3.1开始,SwiftUI不支持针对列表项的自定义滑动操作.根据Apple SDK演变的历史,直到下一个主要的SDK版本(在WWDC 2020年)或更高版本,我们才可能获得支持.

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.

请注意,您必须使用Beta 4或更高版本才能在iOS上使用contextMenu修饰符.

Note that you must be on beta 4 or later to use the contextMenu modifier on iOS.

查看此内容- SwiftUI-列表中的自定义滑动动作

这篇关于SwiftUI-列表编辑模式-如何更改删除按钮标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆