User Rating 0.0 โ˜…โ˜…โ˜…โ˜…โ˜…
Total Usage 0 times
#
Presets:

        
      
Is this tool helpful?

Your feedback helps us improve.

โ˜… โ˜… โ˜… โ˜… โ˜…

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.

hex to uicolor color converter swift color objective-c color hex to rgb kotlin color flutter color css rgb swiftui color xamarin color

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.

channelfloat = parseInt(hexpair, 16)255.0

For a 3-character shorthand like #RGB, each character c is expanded: c โ†’ cc. So #F0A becomes #FF00AA.

R = parseInt(hex[1..2], 16) โ†’ 0 - 255
G = parseInt(hex[3..4], 16) โ†’ 0 - 255
B = parseInt(hex[5..6], 16) โ†’ 0 - 255
A = parseInt(hex[7..8], 16) รท 255.0 โ†’ 0.0 - 1.0

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

PlatformConstructorColor SpaceAlpha SupportValue RangeNotes
Objective-C (UIKit)[UIColor colorWithRed:g:b:a:]sRGBYes0.0 - 1.0CGFloat params
Swift (UIKit)UIColor(red:green:blue:alpha:)sRGBYes0.0 - 1.0CGFloat params
SwiftUIColor(red:green:blue:opacity:)sRGBYes0.0 - 1.0Double params
Kotlin (Android)Color(r, g, b, a)sRGBYes0 - 255 (Int)ARGB Int also common
Flutter / DartColor(0xAARRGGBB)sRGBYes0x00 - 0xFFSingle 32-bit Int
React Nativergba(r, g, b, a) stringsRGBYes0 - 255 + float alphaCSS-like string
CSSrgba(r, g, b, a)sRGBYes0 - 255 + float alphaModern CSS also accepts %
Xamarin (C#)new Color(r, g, b, a)sRGBYes0.0 - 1.0Double params
HEX 3-digit#RGBsRGBNo0 - F per charEach char doubled: F โ†’ FF
HEX 6-digit#RRGGBBsRGBNo00 - FFMost common format
HEX 8-digit#RRGGBBAAsRGBYes00 - FFLast 2 chars = alpha
Integer (Android)0xAARRGGBBsRGBYes32-bit IntAlpha first in byte order
OpenGL / Metalvec4(r, g, b, a)Linear sRGBYes0.0 - 1.0Requires gamma correction
Windows (WPF/UWP)Color.FromArgb(a, r, g, b)sRGBYes0 - 255 (Byte)Alpha param first

Frequently Asked Questions

Each character is doubled to form a 6-digit code. #F0A expands to #FF00AA. The Red channel becomes 0xFF (255), Green becomes 0x00 (0), and Blue becomes 0xAA (170). This is standard CSS shorthand behavior defined in the W3C CSS Color Module Level 4 specification.
The last two characters represent the alpha channel. For example, #663399CC has alpha 0xCC = 204, which normalizes to 204 / 255.0 โ‰ˆ 0.80. Note that Android's integer color format uses ARGB byte order (alpha first: 0xAARRGGBB), while CSS uses RRGGBBAA. This converter follows the CSS/W3C convention for input and adjusts output per platform.
Flutter's Color constructor accepts a single 32-bit integer in 0xAARRGGBB format for performance. The alpha byte comes first because Android's internal color representation is ARGB. Packing four 8-bit channels into one 32-bit integer eliminates four floating-point multiplications per pixel during rendering.
All outputs assume sRGB color space. However, display hardware varies. OLED panels on modern phones have wider gamut (P3) and higher contrast than LCD monitors. iOS automatically maps sRGB to Display P3 on capable devices. For pixel-perfect matching, you would need to use platform-specific extended color space APIs (e.g., UIColor with displayP3 initializer on iOS) rather than sRGB constructors.
Channel values are divided by 255.0 and rounded to 2 decimal places. This gives a maximum error of ยฑ0.005 per channel, which corresponds to less than 1.3 color steps out of 255. For most UI work this is imperceptible. If you need exact values, some platforms accept the raw integer divided by 255.0 expression directly (e.g., 0x66 / 255.0 in Objective-C), preserving full precision at compile time.
Yes. The converter automatically strips or tolerates a missing # prefix. Entering 663399 is equivalent to #663399. It also trims whitespace. However, input must be exactly 3, 6, or 8 valid hexadecimal characters (0-9, A-F) after stripping the prefix, or it will be rejected.