Use Hex color in SwiftUI : <p>in UIKit we could use an Extension to set hex color to almost everything.
<a href="https://www.hackingwithswift.com/example-code/uicolor/how-to-convert-a-hex-color-to-a-uicolor" rel="noreferrer">https://www.hackingwithswift.com/example-code/uicolor/how-to-convert-a-hex-color-to-a-uicolor</a></p>

<p>but when I'm trying to do it on SwiftUI, it's not possible, it looks like the SwiftUI does not get the UIColor as parameter.</p>

<pre><code>    Text(text)
        .color(UIColor.init(hex: "FFF"))
</code></pre>

<p>error message: </p>

<pre><code>Cannot convert value of type 'UIColor' to expected argument type 'Color?'
</code></pre>

<p>I even tried to make an extension for <code>Color</code>, instead of <code>UIColor</code>, but I haven't any luck</p>

<p>my extension for Color:</p>

<p>import SwiftUI</p>

<pre><code>extension Color {
    init(hex: String) {
        let scanner = Scanner(string: hex)
        scanner.scanLocation = 0
        var rgbValue: UInt64 = 0
        scanner.scanHexInt64(&amp;rgbValue)

        let r = (rgbValue &amp; 0xff0000) &gt;&gt; 16
        let g = (rgbValue &amp; 0xff00) &gt;&gt; 8
        let b = rgbValue &amp; 0xff

        self.init(
            red: CGFloat(r) / 0xff,
            green: CGFloat(g) / 0xff,
            blue: CGFloat(b) / 0xff, alpha: 1
        )
    }
}
</code></pre>

<p>error message:</p>

<pre><code>Incorrect argument labels in call (have 'red:green:blue:alpha:', expected '_:red:green:blue:opacity:')
</code></pre>
