Saturday, November 21, 2026
HomeiOS Developmentios - Xcode: Coloration from asset vs Coloration from hex

ios – Xcode: Coloration from asset vs Coloration from hex

[ad_1]

It’s tougher to alter your thoughts in regards to the colours when you hardcode the RGB values.

Suppose Coloration(pink: 0.5, inexperienced: 0.5, blue: 0.5) is the background coloration in your app’s coloration scheme, and you’ve got used this in 10 locations in your code.

If you wish to check out a unique background coloration, you would wish to search out the ten locations you could have written Coloration(pink: 0.5, inexperienced: 0.5, blue: 0.5) and meant that as a background coloration, and alter all these 10 locations. That may be a ache.

In case you as a substitute put the colour within the asset catalog, all it’s good to do to alter the colour is to easily change the contents of the colour within the asset catalog – no code adjustments wanted.

One other drawback of hardcoding the RGB values, is that it’s inconvenient to do completely different colours for darkish mode. You’d must get the @Surroundings(.colorScheme), after which verify like this:

colorScheme == .darkish ? 
    Coloration(pink: 0.8, inexperienced: 0.8, blue: 0.8) : 
    Coloration(pink: 0.1, inexperienced: 0.1, blue: 0.1)

which does not look very good in any respect.

By utilizing an asset catalog title, all of the details about darkish mode and whatnot is within the asset catalog. You’d have much less noise in your code.

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments