Skip to content
Hex Calculator

UIColor to Hex Converter

Convert a Swift UIColor(red:green:blue:alpha:) value back into a 6-digit hex color code by multiplying each normalized float channel by 255.

Hex result
#2563EB

How UIColor to Hex Conversion Works

This tool reads the first three float numbers in a UIColor string — the red, green, and blue components — and multiplies each by 255 to convert it back to a 0-255 channel value, then formats those as a 2-digit hex pair each. It also accepts the bare numbers on their own, without the UIColor(...) wrapper.

UIColor to Hex Example, Step by Step

UIColor(red: 0.145, green: 0.388, blue: 0.922, alpha: 1.0) = #2563EB

UIColor(red: 0.145, green: 0.388, blue: 0.922, alpha: 1.0) = #2563EB

0.145 x 255 = 37 -> 25 (hex)
0.388 x 255 = 99 -> 63 (hex)
0.922 x 255 = 235 -> EB (hex)
StepDescriptionResult
Extract the float channels0.145, 0.388, 0.9223 floats
Multiply each by 2550.145 x 255, 0.388 x 255, 0.922 x 25537, 99, 235
Convert to hex pairs37, 99, 235 -> 25, 63, EB25, 63, EB
Combine with # prefixjoin all three pairs#2563EB

Alpha is ignored — only the red, green, and blue floats feed into the 6-digit hex output.

Common Mistakes With UIColor to Hex

  • Treating the float values as already being 0-255, instead of normalized 0.0-1.0 values that need multiplying.
  • Assuming alpha contributes to the hex output — a plain 6-digit hex code has no alpha channel.
  • Truncating instead of rounding when converting the multiplied result to an integer, which can shift the hex value by one.

Frequently Asked Questions

How does this tool convert UIColor back to hex?

It parses out the first three float numbers it finds in the string, multiplies each by 255, rounds to the nearest integer, and converts the result to a 2-digit hex pair per channel.

Do I need to paste the full UIColor(...) wrapper?

No — the tool also accepts just the bare numbers (0.145, 0.388, 0.922) without the UIColor(red: ... ) wrapper text.

What's the hex value of UIColor(red: 0.145, green: 0.388, blue: 0.922, alpha: 1.0)?

#2563EB — each float is multiplied by 255 (0.145 x 255 = 37, 0.388 x 255 = 99, 0.922 x 255 = 235) then converted to hex.

Does the alpha value affect the hex output?

No — only the first three numbers (red, green, blue) are used. Alpha isn't part of a plain 6-digit hex code.

Why would I need to convert UIColor back to hex?

It's useful for pulling a color out of existing Swift code to reuse in a design tool, a style guide, or a non-Apple codebase.