Home > OS >  Why the Label text disappear when adding its View in a toolbar?
Why the Label text disappear when adding its View in a toolbar?

Time:10-10

I created a View that displays a button which has a Label with name and icon.

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

And it should look like this:

enter image description here

But when I add the View in a toolbar as a toolbar item the text disappear and only the icon remains. Like this:

enter image description here

Any suggestion?

CodePudding user response:

Set titleAndIcon label style to your label, this will make sure to show both title and icon of the label.

Label("change word", systemImage: "arrow.triangle.2.circlepath")
    .labelStyle(.titleAndIcon)
    .fixedSize()
  • Related