iOS Swift Color Generator
ios
static let primary = UIColor(red: 0.231, green: 0.510, blue: 0.965, alpha: 1) static let danger = UIColor(red: 0.937, green: 0.267, blue: 0.267, alpha: 1)
You Might Also Need
The iOS Swift color generator converts named hex colors into UIColor initialisers with floating-point components, ready to paste into a Swift extension.
What is iOS Swift Color Generator?
- The iOS Swift color generator takes a list of named colours and writes one Swift line per entry.
- Two rows are provided to start with, primary and danger, and the Add button appends more, each seeded with a random colour.
- Every row pairs a name field with a colour field and a delete button, and the output panel updates as the rows change.
Each line comes out as a static let declaration whose value is a UIColor initialised with red, green and blue components as decimals between zero and one, plus an alpha of one. That conversion is the substance of the tool. UIKit does not accept hex strings, so a design-file value has to be restated as three fractions, and each division has to be done to enough decimal places that the colour is not visibly shifted. Three decimal places, which is what the output uses, is finer than a screen can show, so the converted colour is identical to the source.
There is a detail in the initialiser choice worth knowing. The form emitted takes components that UIKit interprets in the sRGB space, which is what a hex value from a design tool or a screenshot normally means. If a design system specifies colours in a wider gamut, the conversion here is not the right one, because nothing is being colour-managed — each channel is simply divided by two hundred and fifty-five. For the ordinary case of an sRGB swatch, the result is exact.
The output is a set of declarations rather than a complete file. That is deliberate: paste the lines inside a UIColor extension or a namespace struct and they compile as-is, with the names you typed becoming the accessors. There is no wrapper to reconcile and no naming convention imposed, so the token file and the call sites use the same words.
When typing names, match what Swift expects: lowerCamelCase, and a valid identifier, since these become property names. Alpha is always one, so translucent colours cannot be expressed here — those are usually handled at the point of use in Swift anyway, with an opacity modifier applied to an opaque base colour. There is also no dark-mode variant and no asset catalogue output: a colour that has to differ between light and dark appearance needs either a dynamic initialiser or an asset entry, neither of which this page produces. And the lines carry no comments, so a large set benefits from grouping when it is pasted.
Being clear about the boundaries helps too: the output is a block of declarations rather than a file, so it needs a home inside an existing extension before it compiles. There is no asset-catalogue export, no dark-mode variant, and no wider-gamut initialiser, so a design system that relies on any of those will need edits after pasting. Compared with the other native exporters, this one sits alongside Android resources, Flutter constants and Figma tokens, sharing the same row interface with a different output. Used as an ios swift color generator, it removes the arithmetic that would otherwise be done by hand for every token: name the colours, copy the swift uicolor code, and paste the ios color constants into a swift color palette code file with the uicolor from hex conversion already done.
How to use iOS Swift Color Generator
- Type the token names in the left column, using valid lowerCamelCase Swift identifiers.
- Set each colour with the field beside its name, or add rows with Add.
- Copy the declarations and paste them inside a UIColor extension or namespace struct.
When to use iOS Swift Color Generator vs related tools
Use this when an iOS project needs a block of colour constants converted from a palette. Use the Flutter or Android exporters for those platforms, or the design token generator when the colours need to travel as a document instead of as code. Before the hex becomes a UIColor literal, the color format converter shortens the checking, and a palette that arrives as a token document rather than rows is the figma token generator's output.
Privacy & Security
This tool runs entirely in your browser — no data ever leaves your device. There is no server round-trip, no upload, no logging, and no account required. Your input is processed locally using client-side JavaScript and is never stored, transmitted, or accessible to anyone else. When you close the tab, everything disappears.