GO FURTHER, FASTER: Try the Swift Career Accelerator today! >>

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      

Go further, faster with the Swift Career Accelerator.

GO FURTHER, FASTER Unleash your full potential as a Swift developer with the all-new Swift Career Accelerator: the most comprehensive, career-transforming learning resource ever created for iOS development. Whether you’re just starting out, looking to land your first job, or aiming to become a lead developer, this program offers everything you need to level up – from mastering Swift’s latest features to conquering interview questions and building robust portfolios.

Learn more here

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.