How to convert `UIColor` to SwiftUI‘s `Color`

Starting with beta 5, you can create a Color from a UIColor:


Both iOS and macOS

Color has a native initializer for it that takes an UIColor or NSColor as an argument:

Color(.red) /* or any other UIColor/NSColor you need INSIDE parentheses */

DO NOT call Color( explicitly !!!. This will couple your SwiftUI code to the UIKit. Instead, just call Color(.red) That will infer the correct module automatically.

Also, Note this difference:     /* this `red` is SwiftUI native `red` */
Color(.red)   /* this `red` is UIKit `red` */

suColor vs uiColor

Note that: and are NOT same! They have different values and look different with each other. So DON'T assume this worth nothing

These are equal instead: SwiftUI.Color.Red == UIKit.UIColor.systemRed


You can implement a custom variable for it to make it more like cgColor and ciColor

extension UIColor {
    /// The SwiftUI color associated with the receiver.
    var suColor: Color { Color(self) }

so it would be like:         // UIKit color // SwiftUI color // Core graphic color // Core image color

Using two helper extensions:

To extract components from UIColor:

extension UIColor {
    var rgba: (red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) {
        var red: CGFloat = 0
        var green: CGFloat = 0
        var blue: CGFloat = 0
        var alpha: CGFloat = 0
        getRed(&red, green: &green, blue: &blue, alpha: &alpha)

        return (red, green, blue, alpha)

To init with UIColor:

extension Color {
    init(uiColor: UIColor) {
        self.init(red: Double(,
                  green: Double(,
                  blue: Double(,
                  opacity: Double(uiColor.rgba.alpha))


Color(uiColor: .red)