swiftui uicolor to color code example
Example 1: uicolor from hex swift
extension UIColor {
convenience init(hexaString: String, alpha: CGFloat = 1) {
let chars = Array(hexaString.dropFirst())
self.init(red: .init(strtoul(String(chars[0...1]),nil,16))/255,
green: .init(strtoul(String(chars[2...3]),nil,16))/255,
blue: .init(strtoul(String(chars[4...5]),nil,16))/255,
alpha: alpha)}
}
let redColor = UIColor(hexaString: "#FF0000")
let transparentRed = UIColor(hexaString: "#FF0000", alpha: 0.5)
Example 2: swift set uicolor
let swiftColor = UIColor(red: 1, green: 165/255, blue: 0, alpha: 1)