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

How to display a UIImage with SFSymbol using SwiftUI Image?

I have an Image which displays it’s contents using UIImage objects that are passed in. There is now a need to display an SFSymbol in the Image. I am testing in a separate sample if it was possible to do so using a UIImage with systemName which is the SFSymbol name. However, the following code doesn’t render any image.

struct ContentView: View {
    var body: some View {
        VStack {
            Image(uiImage: UIImage(systemName: "airplane.circle.fill")!.withRenderingMode(.alwaysOriginal))
                .resizable()
                .aspectRatio(contentMode: .fit)
                .frame(width: 150, height: 150)
        }
        .background {
            Color.black.ignoresSafeArea()
        }
    }
}

I know I could just use the systemName initialiser for Image with the symbol name but unfortunately it is not possible to do so due to some constraints. Is it possible to do the required? Any help is appreciated.

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

>Solution :

You’re drawing a black image on a black background.

Change Color.black.ignoresSafeArea() to any other color to e.g. Color.white.ignoresSafeArea() to make the image appear.

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