---
title: "Discussion on \"From Hex to Color and Back in SwiftUI\" | Hashnode"
description: "Discussion on \"From Hex to Color and Back in SwiftUI\". How to convert SwiftUI Color into Hex and from Hex into Color with help of UIColor or CGColor respectively. Extension implementations are shared."
url: "https://hashnode.com/posts/from-hex-to-color-and-back-in-swiftui/62139d2ef56c896b3792f1f2"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [From Hex to Color and Back in SwiftUI](https://blog.eidinger.info/from-hex-to-color-and-back-in-swiftui?utm_source=hashnode&utm_medium=feed)

How to convert SwiftUI Color into Hex and from Hex into Color with help of UIColor or CGColor respectively. Extension implementations are shared.

Feb 21, 2022 · 3 min read · blog.eidinger.info  
Read the article

-   [#ios](https://hashnode.com/tag/ios)
-   [#swift](https://hashnode.com/tag/swift)

## Written by

[Marco Eidinger](https://hashnode.com/@MarcoEidinger)

@MarcoEidinger

  
[View profile](https://hashnode.com/@MarcoEidinger)

#Swift #iOS SDK architect 🇺🇸 🇩🇪

I am a Software Engineer working on open source and enterprise mobile SDKs for iOS and MacOS developers written in Swift. From 🇩🇪 and happily living in 🇺🇸

## Responses 1

Markdown supported · ⌘↵ to post

[Maximiliano taccone](https://hashnode.com/@MaxxANDROIDIOS)

[Jul 20, 2023](https://hashnode.com/posts/from-hex-to-color-and-back-in-swiftui/62139d2ef56c896b3792f1f2/comment/64b97800a884f3de56a27168)

Hello!!! thanks for the blog.!! An erro is in RGBA HexToUIColor

This works OK..

a = CGFloat((hexNumber & 0xff000000) >> 24) / 255 r = CGFloat((hexNumber & 0x00ff0000) >> 16) / 255 g = CGFloat((hexNumber & 0x0000ff00) >> 8) / 255 b = CGFloat(hexNumber & 0x000000ff) / 255

Best for you!! Maximiliano Taccone
