Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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?

>Solution :

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()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading