为什么在工具栏中添加其视图时标签文本消失?

Lor*_*rri 4 label toolbar button swift swiftui

我创建了一个视图,显示一个按钮,其中有一个带有名称和图标的标签。

struct NewWordButtonView: View {

    @State var isAlert: Bool = false

    var body: some View {
        Button {
            isAlert.toggle()
        } label: {
            Label("change word", systemImage: "arrow.triangle.2.circlepath").fixedSize()
        }
    .buttonStyle(.bordered)
    }
}
Run Code Online (Sandbox Code Playgroud)

它应该看起来像这样:

在此输入图像描述

但是,当我将视图添加到工具栏中作为工具栏项时,文本消失,仅保留图标。像这样:

在此输入图像描述

有什么建议吗?

Nir*_*v D 6

titleAndIcon将标签样式设置为您的label,这将确保显示标签的标题和图标。

Label("change word", systemImage: "arrow.triangle.2.circlepath")
    .labelStyle(.titleAndIcon)
    .fixedSize()
Run Code Online (Sandbox Code Playgroud)