Search
 
SCRIPT & CODE EXAMPLE
 

SWIFT

swift hex color

//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)
    )
}

Comment

hex color swiftui

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

PREVIOUS NEXT
Code Example
Swift :: swift convert base64 string to data 
Swift :: swift hello world 
Swift :: Delete Realm database swift 
Swift :: Swift Basic Input 
Swift :: changing color of background swift 
Swift :: swiftui searchbar 
Swift :: rxswift combine two observables 
Swift :: how to add an underline to a textField swift 
Swift :: swift close view 
Swift :: how to set the font of text in swiftui 
Swift :: sf symbols 
Swift :: string interpolation swift 5 
Swift :: swift dictionary sorted 
Swift :: accessing tab bar item action swift 
Swift :: swift extension Array with type 
Swift :: uibutton swift set title 
Swift :: swift enum nib 
Swift :: two value sum 
Swift :: swift comment 
Swift :: Swift for Loop with where Clause 
Swift :: Logical Operators Swift 
Swift :: Swift Conform Class To Swift Protocol 
Swift :: Swift Code Reusability 
Swift :: swift constants 
Swift :: swiftui profile picture 
Swift :: how request prefix of string in swift 
Swift :: swift split an array into chunks 
Swift :: swiftui show custom loading spinner 
Swift :: uialertcontroller example objective Code Answer 
Ruby :: rails mimemagic issue 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =