“Hex Color SwiftUi” Kode Jawaban

Hex Color SwiftUi

"Color sets can be added in the Assets.xcassets of your project, which you can use throughout your views."
sirchamallow

warna hex cepat

//https://stackoverflow.com/questions/24263007/how-to-use-hex-color-values
var color1 = hexStringToUIColor("#d3d3d3")

//Create Func
func hexStringToUIColor (hex:String) -> UIColor {
    var cString:String = hex.trimmingCharacters(in: .whitespacesAndNewlines).uppercased()

    if (cString.hasPrefix("#")) {
        cString.remove(at: cString.startIndex)
    }

    if ((cString.count) != 6) {
        return UIColor.gray
    }

    var rgbValue:UInt64 = 0
    Scanner(string: cString).scanHexInt64(&rgbValue)

    return UIColor(
        red: CGFloat((rgbValue & 0xFF0000) >> 16) / 255.0,
        green: CGFloat((rgbValue & 0x00FF00) >> 8) / 255.0,
        blue: CGFloat(rgbValue & 0x0000FF) / 255.0,
        alpha: CGFloat(1.0)
    )
}

Lucky Lapwing

Jawaban yang mirip dengan “Hex Color SwiftUi”

Pertanyaan yang mirip dengan “Hex Color SwiftUi”

Lebih banyak jawaban terkait untuk “Hex Color SwiftUi” di Swift

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya