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.

Built by
Swapnil SanghviFull-Stack Web Developer & WordPress Developer
Swapnil Sanghvi is a full-stack web and WordPress developer, UI designer, and full-time freelancer who builds and maintains Hex Calculator.
Further reading: CSS Colors — W3Schools
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)
| Step | Description | Result |
|---|---|---|
| Extract the float channels | 0.145, 0.388, 0.922 | 3 floats |
| Multiply each by 255 | 0.145 x 255, 0.388 x 255, 0.922 x 255 | 37, 99, 235 |
| Convert to hex pairs | 37, 99, 235 -> 25, 63, EB | 25, 63, EB |
| Combine with # prefix | join all three pairs | #2563EB |
Alpha is ignored — only the red, green, and blue floats feed into the 6-digit hex output.
Where UIColor to Hex Actually Comes Up
Auditing a Legacy App's Color Usage
Extracting hex values from scattered UIColor calls across an old codebase is a useful first step before consolidating everything into a proper design system.
UIColor call -> hex for audit list
Matching a Companion Website to an iOS App
Converting a UIColor from the app's code to hex gives web developers the exact value needed to keep a marketing site or web app visually consistent.
app UIColor -> web CSS hex
Reverse-Engineering a Color From Open Source Code
When reading someone else's Swift code and wanting to know what a UIColor actually looks like, converting it to hex lets you preview or reuse it elsewhere.
found in code -> visual hex reference
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.
Why Use This Calculator Instead of Doing the Math Yourself
- Accepts the full UIColor(...) wrapper or just the bare numbers
- Runs entirely in your browser — nothing you type gets sent anywhere
- Rounds correctly instead of truncating, avoiding an off-by-one hex shift
- Ignores alpha automatically, since plain hex has no transparency channel
Limitations
- Expects normalized 0-1 component values, not 0-255 — a UIColor initialized with 0-255 values will read as out of range.
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.
How do I document a legacy app's colors for a redesign?
Extract the hex value from each UIColor call in the existing codebase to build a color inventory — a useful first step before consolidating an app's colors into a proper design system.
Can I use this to port a UIKit color to a web project?
Yes — converting a UIColor value to hex gives you a color you can drop directly into CSS, making it easy to keep a companion website visually consistent with an iOS app.