Skip to content

HEX to SwiftUI Color

Turn a HEX code into SwiftUI Color, UIColor and NSColor code.

The colour

Used by the Asset Catalog output.

Swift
The Swift code appears here

Quick Tool Overview

HEX to SwiftUI Color writes the code rather than the numbers: a SwiftUI Color, a UIColor, an NSColor, the hex-string extension most projects end up writing, and the Asset Catalog JSON that gives you dark mode for free.

What it does
Turns a HEX colour into Swift colour code
You give it
A HEX code from a design file
You get back
SwiftUI, UIKit and AppKit code, ready to paste
Best for
iOS and macOS work from a design handoff
Color Tools Free, unlimited use No sign-up Runs in your browser

About the HEX to SwiftUI Color

Neither SwiftUI nor UIKit takes a hex string. Both want floating-point components between 0 and 1, which means every colour from a design handoff has to be divided by 255 three times before it can be used.

This does that and writes the code. You get a SwiftUI Color initialiser, a UIColor for UIKit, an NSColor for AppKit, and the hex-string extension that most projects end up writing anyway, ready to paste into a shared file.

The Asset Catalog snippet is worth taking instead, for anything that needs a dark mode variant. Colours defined in an asset catalog get light and dark appearances for free and are resolved by the system, which is cleaner than branching on colorScheme in a view. The tool emits the JSON the catalog stores, with the sRGB colour space set explicitly.

Key features of the HEX to SwiftUI Color

Components already normalised

Core Graphics wants 0–1 floats, so the division by 255 is done for you at full precision.

Three frameworks

SwiftUI Color, UIColor for UIKit and NSColor for AppKit, so the right one is always there.

The hex extension

The Color(hex:) initialiser every project writes eventually, correct and ready for a shared file.

Asset Catalog JSON

The better route for design system colours, since the catalog handles light, dark and high-contrast appearances.

sRGB stated explicitly

The colour space is set in the output rather than left to a default, which is where wide-gamut surprises come from.

How to use the HEX to SwiftUI Color

  1. 1

    Enter your HEX colour

    From a design file, a brand guide or the picker.

  2. 2

    Choose the framework

    SwiftUI Color, UIColor or NSColor — or take all three.

  3. 3

    Copy the code

    Ready to paste, with the components already normalised.

  4. 4

    Or take the asset JSON

    The Asset Catalog form, which gives you a dark mode variant properly.

Frequently asked questions

Because Core Graphics works in normalised floats throughout, which keeps it independent of bit depth. A 10-bit display and an 8-bit one use the same API.

Reviews of the HEX to SwiftUI Color

What people who use the HEX to SwiftUI Color think of it. Reviews come from visitors and are posted as written.

No ratings yet

Yours would be the first.

  • 5 0 reviews rated 5 stars
  • 4 0 reviews rated 4 stars
  • 3 0 reviews rated 3 stars
  • 2 0 reviews rated 2 stars
  • 1 0 reviews rated 1 star

Write a review

Used this tool? Your rating helps the next person decide.

Your rating

Plain text only — links, email addresses and HTML are not accepted. Your name and review are shown publicly; nothing else is collected. See the privacy policy.

0 reviews

Newest first

No reviews yet

Be the first to rate the HEX to SwiftUI Color. It takes half a minute and no account.

Write the first review

More color tools