NEW: My new book Pro SwiftUI is out now – level up your SwiftUI skills today! >>

How do you add a custom .svg symbol to SwiftUI?

Forums > SwiftUI

I had a designer create a custom sysmbol using Apple's SF Symbols documentation. They gave me an .svg file that I dutifuly added to the asset catalogue (again using Apple's documentation) but when I tried using it in a view it does not appear to be rendering as expected so is there some other step required to make these things work in SwiftUI?


How is it rendering?

All you have to do is import your properly formatted SVG (and "properly formatted" is very important) into your assets catalog, then you can use it in your code like this:

let img = UIImage(named: "yourImageName")

You can adjust various properties of the image using SymbolConfiguration, as per Apple's docs.

For mine, I created an extension on UIImage to make it easier to create an image in different scales.

extension UIImage {
    static func catHeadImage(filled: Bool = false, scale: SymbolScale) -> UIImage {
        let config = UIImage.SymbolConfiguration(scale: scale)
        return (UIImage(named: filled ? "cat.head.fill" : "cat.head")!.withConfiguration(config).withRenderingMode(.alwaysTemplate))


Hacking with Swift is sponsored by Play

SPONSORED Play is the first native iOS design tool created for designers and engineers. You can install Play for iOS and iPad today and sign up to check out the Beta of our macOS app with SwiftUI code export. We're also hiring engineers!

Click to learn more about Play!

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.