BLACK FRIDAY SALE: Save 50% on all my Swift books and bundles! >>

How to configure your UI System Image programatically?

Forums > Swift

Hey guys. Ive got my system image in my enum

static let plusLarge                = UIImage(systemName: "plus",
                                                  withConfiguration: UIImage.SymbolConfiguration(scale: .large))

As you can see I have managed to configure its scale, but on top of that I would also like to specify weight's value for that system image. I've tried few tricks but at the end of the day I have no idea how to add both, scale and weight at once.

Many thank for any help.


If you doing it SwiftUI there is a great video by Stewart Lynch Two SwiftUI Enum Use Cases, maybe look at this and you might be able to use similar for Swift


It looks like your options are limited. UISymbolConfiguration has the following initializers:

init(pointSize: CGFloat)
init(pointSize: CGFloat, weight: UIImage.SymbolWeight)
init(pointSize: CGFloat, weight: UIImage.SymbolWeight, scale: UIImage.SymbolScale)
init(scale: UIImage.SymbolScale)
init(textStyle: UIFont.TextStyle)
init(textStyle: UIFont.TextStyle, scale: UIImage.SymbolScale)
init(weight: UIImage.SymbolWeight)
init(font: UIFont)
init(font: UIFont, scale: UIImage.SymbolScale)

As you can see, there's no combination that lets you pass in a scale and a weight unless you also give it a point size or a complete UIFont object (which can have a weight as one of its properties). You might think you could supply a system font of the desired weight, but you would still need to give it a point size in the UIFont initializer.

Unless I'm missing something, you can't create a UIImage.SymbolConfiguration with just a weight and a scale.


Hacking with Swift is sponsored by Guardsquare

SPONSORED AppSweep by Guardsquare helps developers automate the mobile app security testing process with fast, free scans. By using AppSweep’s actionable recommendations, developers can improve the security posture of their apps in accordance with security standards like OWASP.

Learn more

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.