Hex to UIColor Converter
Convert a hex color like #2563EB into Swift UIColor(red:green:blue:alpha:) syntax with normalized 0.0-1.0 float components, ready to paste into Xcode.

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 Hex to UIColor Conversion Works
UIKit's UIColor initializer expects red, green, blue, and alpha as normalized floats between 0.0 and 1.0, not the 0-255 integers hex codes pack. This tool splits the hex code into its three channels, divides each by 255, and formats the result to 3 decimal places as a ready-to-paste UIColor(...) call.
Hex to UIColor Example, Step by Step
#2563EB = UIColor(red: 0.145, green: 0.388, blue: 0.922, alpha: 1.000)
#2563EB (hex) = UIColor(red: 0.145, green: 0.388, blue: 0.922, alpha: 1.000)
Split into pairs: 25 | 63 | EB 25 (hex) = 37 -> 37 / 255 = 0.145 63 (hex) = 99 -> 99 / 255 = 0.388 EB (hex) = 235 -> 235 / 255 = 0.922
| Step | Description | Result |
|---|---|---|
| Split the hex code | #2563EB -> 25, 63, EB | 3 byte pairs |
| Convert to decimal | 25, 63, EB -> 37, 99, 235 | 37, 99, 235 |
| Normalize each channel | divide by 255 | 0.145, 0.388, 0.922 |
| Format as UIColor | add alpha: 1.000 | UIColor(red: 0.145, green: 0.388, blue: 0.922, alpha: 1.000) |
Alpha is always 1.000 for a plain hex conversion since hex codes carry no transparency information on their own.
Where Hex to UIColor Actually Comes Up
Adding a Brand Color to a UIKit View
Implementing a design spec's color in a UIKit-based screen needs the exact UIColor initializer syntax — this produces it directly from the spec's hex value.
#2563EB -> UIColor(red: 0.145, ...)
Maintaining a Legacy Objective-C Codebase
Older iOS projects still using Objective-C-bridged UIKit code need the same UIColor(red:green:blue:alpha:) syntax when adding or updating colors.
legacy hex constant -> UIColor call
Building a UIColor Extension for a Design System
Centralizing an app's palette in a UIColor extension means converting each design token's hex value into this exact initializer format.
design token -> UIColor extension entry
Common Mistakes With Hex to UIColor
- Passing 0-255 integers directly into UIColor's red:green:blue: parameters instead of normalized 0.0-1.0 floats.
- Forgetting the alpha: parameter, which UIColor's designated initializer requires.
- Rounding channel values too aggressively, which can produce a visibly different color at low precision.
Why Use This Calculator Instead of Doing the Math Yourself
- Handles the byte-to-float division and rounding for you
- Runs entirely in your browser — nothing you type gets sent anywhere
- Outputs valid, ready-to-paste Swift syntax including alpha
- Formats to a consistent, readable 3 decimal places
Limitations
- Converts exactly (no nearest-match approximation) — this is a direct reformatting of the same RGB values into that platform's color initializer syntax.
Frequently Asked Questions
Why does UIColor use 0.0-1.0 instead of 0-255?
iOS and macOS UIKit's UIColor initializer takes normalized float components between 0.0 and 1.0 rather than 0-255 integers. This tool divides each RGB channel by 255 and formats the result to 3 decimal places.
What's the UIColor value of #2563EB?
UIColor(red: 0.145, green: 0.388, blue: 0.922, alpha: 1.000) — each channel divided by 255 and rounded to 3 decimals.
Can I paste this directly into Swift code?
Yes, the output is valid Swift syntax for the UIColor initializer and can be pasted directly into a Swift or Objective-C-bridged file.
Does the alpha value ever change?
This tool always outputs alpha: 1.000 (fully opaque) since a plain hex code has no alpha channel of its own.
Is there precision loss from rounding to 3 decimals?
It's negligible for display purposes — 3 decimal places is precise enough that the resulting color is visually indistinguishable from the original hex value.
How do I add a brand color to a UIKit-based app?
Convert the hex value here and paste the UIColor(...) call into a UIColor extension or wherever your app defines reusable colors, keeping UIKit views consistent with the design spec.
Is this useful for maintaining a legacy Objective-C project?
Yes — UIColor(red:green:blue:alpha:) works the same in Objective-C-bridged code, so this conversion is just as useful when porting or maintaining an older UIKit codebase.