Hex to UIColor Converter

The Hex to UIColor Converter takes the value you enter in Hex Color and converts it into Apple's UIColor(red:green:blue:alpha:) float syntax for Swift and iOS. Click Convert and paste the result straight from Swift UIColor Output into your Xcode project. Enter your red, green, blue, and alpha values into the rgba to hex converter and it returns the matching hex output with transparency preserved.

Convert Hex Colors to Swift UIColor Syntax

This tool takes a hex color in #RRGGBB format (or the shorthand #RGB form) and produces the matching UIColor(red:green:blue:alpha:) initializer call for Swift. Each hex channel is decomposed into red, green, and blue, then normalized from the 0–255 integer range to the 0.0–1.0 float range that UIKit's UIColor expects. Paste a hex color into the hex to pantone converter and it returns the nearest match from its reference list, flagged as unofficial.

The Normalization Formula

The math behind every conversion is the same simple division, applied to each channel:

$$\text{float value} = \frac{\text{hex channel (0–255)}}{255}$$

The result is formatted to three decimal places, which is what the converter's output actually shows — a value like 64 doesn't round to a clean 0.25, it comes out as 0.251, since 64 ÷ 255 = 0.25098....

Example — Pure White (#FFFFFF)

The simplest baseline: all three channels are at maximum (255), which normalizes to 1.000 across the board.

Swift UIColor Output:
UIColor(red: 1.000, green: 1.000, blue: 1.000, alpha: 1.0)

Example — A Brand Blue (#4080BF)

Here the hex channels 0x40, 0x80, and 0xBF decode to 64, 128, and 191. Dividing each by 255 gives the normalized floats:

$$R = \frac{64}{255} \approx 0.251, \quad G = \frac{128}{255} \approx 0.502, \quad B = \frac{191}{255} \approx 0.749$$
Swift UIColor Output:
UIColor(red: 0.251, green: 0.502, blue: 0.749, alpha: 1.0)

Example — A Warm Orange (#FF6600)

Swift UIColor Output:
UIColor(red: 1.000, green: 0.400, blue: 0.000, alpha: 1.0)

Paste the result straight from the Swift UIColor Output field into your Xcode project — for example, directly inside a UIView's backgroundColor assignment: view.backgroundColor = UIColor(red: 0.251, green: 0.502, blue: 0.749, alpha: 1.0).

Alpha channel note: This converter always outputs alpha: 1.0 (fully opaque) — it parses standard 6-digit and shorthand 3-digit hex colors, not 8-digit hex-plus-alpha input. If you need a specific alpha value in your UIColor call, generate the RGB portion here and edit the alpha: parameter by hand afterward.
Infographic showing how to convert hex #2E8F5C to Swift's UIColor: split into hex pairs, convert to decimal, then divide each by 255 to get UIColor(red: 0.180, green: 0.561, blue: 0.361)
Hex to UIColor Converter: #2E8F5C = UIColor(red: 0.180, green: 0.561, blue: 0.361)

Why Developers Rely on a Hex to UIColor Converter

Bridging design with engineering is one of the most friction-heavy parts of iOS and macOS app building. Design tools like Figma and Sketch export colors as hex codes or RGB values — but UIKit's UIColor has no built-in hex-string initializer in the standard SDK, so every hex color from a design handoff has to be manually decomposed into normalized red, green, and blue floats before it's usable in Swift. Doing that arithmetic by hand for an entire design system's color palette is tedious and a real source of small, hard-to-spot rounding mistakes.

  • UI consistency: Every color in your app matches the design file exactly — no manual division errors causing off-brand shades.
  • Faster prototyping: Swap colors while iterating on a screen without breaking your flow to do channel math by hand.
  • Cross-platform color parity: Keep the same hex-based palette as your web frontend or design tokens, converting to Swift UIColor syntax only where iOS/macOS code actually needs it.
  • Fewer rounding mistakes: A hand-computed 64 / 255 is easy to round sloppily to 0.25; the converter always returns the precise three-decimal value.

Where UIColor Fits in iOS and macOS Development

UIColor is Apple's UIKit class for representing colors in iOS and macOS apps — every view, layer, and text element that needs a color accepts a UIColor object, whether that's a predefined system color like UIColor.systemBlue or a custom color built from your own RGB components. This converter handles exactly that second case: turning your own hex-based brand or design-system color into the UIColor(red:green:blue:alpha:) call you'd otherwise have to write out by hand.

Frequently Asked Questions About Hex to UIColor Conversion

Why do I need to convert hex colors to UIColor at all?

UIKit's UIColor has no native hex-string initializer in the standard SDK — every hex color from a design file has to be manually broken into normalized red, green, and blue float components (each divided by 255) before you can use it in Swift. Doing this by hand for every color in a large design system costs time and introduces rounding mistakes; this converter makes it instant and precise.

Does the output include the alpha channel?

The output always includes an alpha: parameter, but it's fixed at 1.0 (fully opaque) — this converter parses standard 6-digit and shorthand 3-digit hex colors only, not an 8-digit hex-plus-alpha format. If you need a specific opacity, adjust the alpha: value in the generated code by hand.

Is there a difference between RGB and hex values?

Not in the underlying color data — both representations encode the same information. A hex color like #4080BF is simply a compact base-16 encoding of three integer RGB values: red 64, green 128, blue 191. Split the six-character hex string into pairs (rr, gg, bb), convert each pair from base-16 to base-10, and you have your RGB integers — which this converter then divides by 255 to produce UIColor's normalized floats.

Can I convert UIColor back to a hex color?

Yes — use this site's UIColor to Hex Converter to go the other direction: enter your UIColor(red:green:blue:alpha:) values (or the equivalent 0.0–1.0 floats) and get back the original hex code, useful when you need to move a color defined in Swift back into CSS or a shared design token.

Does this tool support shorthand 3-digit hex codes?

Yes — a shorthand code like #F80 is expanded to #FF8800 automatically before the RGB channels are normalized, so you don't need to type out the full six digits.

Does this tool send my data anywhere?

No. The conversion runs entirely in your browser using client-side JavaScript. Nothing you type is uploaded or stored.