Hex Color to UIColor Converter
Convert HEX color codes to UIColor (Swift, Obj-C), Kotlin, Flutter, SwiftUI, Xamarin, CSS, and React Native color definitions instantly.
About
Manually translating HEX color codes to platform-specific color constructors is error-prone. A misplaced nibble in R, G, or B channels shifts hue by up to 16 steps per digit, producing visually wrong results that pass code review unnoticed. This converter parses standard 3-digit, 6-digit, and 8-digit (with alpha) HEX strings and outputs normalized color definitions for 8 platforms: Objective-C UIColor, Swift UIColor, SwiftUI Color, Kotlin, Flutter/Dart, React Native, CSS rgba, and Xamarin C#. Each channel value is divided by 255.0 to produce the correct floating-point representation required by native APIs. The tool assumes sRGB color space. Note: platform renderers may apply gamma correction differently, so colors may appear slightly different on OLED vs LCD panels.
Formulas
A HEX color string encodes each channel as a base-16 pair. The conversion extracts integer values per channel and normalizes them for APIs that expect floating-point input.
For a 3-character shorthand like #RGB, each character c is expanded: c โ cc. So #F0A becomes #FF00AA.
Where R = Red channel, G = Green channel, B = Blue channel, A = Alpha (opacity). If no alpha pair is present, A defaults to 1.0 (fully opaque).
Reference Data
| Platform | Constructor | Color Space | Alpha Support | Value Range | Notes |
|---|---|---|---|---|---|
| Objective-C (UIKit) | [UIColor colorWithRed:g:b:a:] | sRGB | Yes | 0.0 - 1.0 | CGFloat params |
| Swift (UIKit) | UIColor(red:green:blue:alpha:) | sRGB | Yes | 0.0 - 1.0 | CGFloat params |
| SwiftUI | Color(red:green:blue:opacity:) | sRGB | Yes | 0.0 - 1.0 | Double params |
| Kotlin (Android) | Color(r, g, b, a) | sRGB | Yes | 0 - 255 (Int) | ARGB Int also common |
| Flutter / Dart | Color(0xAARRGGBB) | sRGB | Yes | 0x00 - 0xFF | Single 32-bit Int |
| React Native | rgba(r, g, b, a) string | sRGB | Yes | 0 - 255 + float alpha | CSS-like string |
| CSS | rgba(r, g, b, a) | sRGB | Yes | 0 - 255 + float alpha | Modern CSS also accepts % |
| Xamarin (C#) | new Color(r, g, b, a) | sRGB | Yes | 0.0 - 1.0 | Double params |
| HEX 3-digit | #RGB | sRGB | No | 0 - F per char | Each char doubled: F โ FF |
| HEX 6-digit | #RRGGBB | sRGB | No | 00 - FF | Most common format |
| HEX 8-digit | #RRGGBBAA | sRGB | Yes | 00 - FF | Last 2 chars = alpha |
| Integer (Android) | 0xAARRGGBB | sRGB | Yes | 32-bit Int | Alpha first in byte order |
| OpenGL / Metal | vec4(r, g, b, a) | Linear sRGB | Yes | 0.0 - 1.0 | Requires gamma correction |
| Windows (WPF/UWP) | Color.FromArgb(a, r, g, b) | sRGB | Yes | 0 - 255 (Byte) | Alpha param first |