Search code examples
imageswiftuilabel

SwiftUI Label with dynamic image


It is possible to use a dynamic image within a Label ?

Something like :

Label("SP98", uiImage: myFunctionToReturnImageFromText("test"))

used in this context :

Menu {
                            
                            if fuelTypeisAvailable(fuelType: "Diesel") {
                                
                                Button {
                                    updateStuff()
                                    Haptics.shared.play(.light)
                                    preferredFuelType = "Diesel"
                                    
                                } label: {
                                    Label("Diesel", systemImage: "fuelpump.circle")
                                   
                  

          }
                        }

Thanks


Solution

  • I think the initializer that you want to use is:

    Label {
       Text("SP98")
    } icon: {
       Image(uiImage: myFunctionToReturnImageFromText("test"))
    
    }