UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

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.

3      

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

3      

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.

3      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out 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.