HEX to UIColor Converter

This is a HEX to UIColor converter for Swift. #2563EB is UIColor(red: 0.145, green: 0.388, blue: 0.922, alpha: 1.000). Also SwiftUI, NSColor and Objective-C.

Examples — click a swatch

Click a value to copy it

Convert several colors at once. One per line, or commas such as #3B82F6, #FF573380. Fill example loads three rows and the table below.

HEX to UIColor

This is a HEX to UIColor converter for Swift and UIKit. Channels are floats from 0 to 1, not 0–255. #2563EB is UIColor(red: 0.145, green: 0.388, blue: 0.922, alpha: 1.000). The same page prints SwiftUI, NSColor and Objective-C. HEX to RGBA is the CSS form of those channels.

How to use

  1. Paste HEX, short #RGB, 8-digit HEX8, rgb(), or a UIColor / Color / NSColor line. Pick a color, or pick from screen where EyeDropper is available.
  2. Each snippet has Copy. Copy result copies the Swift UIKit line. Click a channel chip to copy 0–1 floats or HEX.
  3. Show example loads #2563EB. Swatches include #2563EB, #3B82F6, #16A34A, #1E293B, #DC2626, white, black and #2563EB80.
  4. Batch prints one Swift UIKit line per input. Clear all empties the boxes.

Notes

Each channel is byte / 255, then three decimals: 37/255 → 0.145, 99/255 → 0.388, 235/255 → 0.922. Alpha is 1.000 for 6-digit HEX; 8-digit HEX uses the last two bytes (80 hex ≈ 0.502). UIColor /255 keeps the integers so you can see 37/255 next to 0.145. Invalid HEX shows an error instead of crashing. Related: HEX to RGBA, Color Converter.

Where to use it

  • Pasting a design HEX into a UIKit view or a UIColor extension.
  • Keeping a SwiftUI Color in step with the same token.
  • macOS AppKit via NSColor, or an older Objective-C file.

Questions

Why 0–1 instead of 0–255?

UIColor(red:green:blue:alpha:) takes floats. Passing 37, 99, 235 looks washed out or wrong. Use the /255 line if you prefer integers in source.

Does alpha ever change?

Six-digit HEX is 1.000. Eight-digit HEX8, such as #2563EB80, sets alpha from the last byte.

Is three decimals enough?

Yes for UI. 0.145 vs 37/255 is not a visible shift on a screen.