Search
 
SCRIPT & CODE EXAMPLE
 

SWIFT

hex color extension swift

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

PREVIOUS NEXT
Code Example
Swift :: try? as? in swiftui 
Swift :: most frequent element in array swift 
Swift :: swift date to string 
Swift :: hex color swiftui 
Swift :: swift calendar components 
Swift :: swiftui create search bar 
Swift :: set right bar button item swift 
Swift :: change background color of uitableview section header 
Swift :: swift 5 make image fit uiimageview 
Swift :: swiftui coin flip 
Swift :: swift inheritance 
Swift :: swift create an empty array 
Swift :: swiftui tabview background color 
Swift :: swift uilabel dynamic height based on text length 
Swift :: swift extension Array of type 
Swift :: swift how to set warning message 
Swift :: swift dictionary 
Swift :: two variable sum in swift 
Swift :: swift go to main thread 
Swift :: swift apply changes after a word in string 
Swift :: waiting for all the threads to finish swift 
Swift :: Swfit Add Elements to an Array 
Swift :: Swift Dictionary Inside a Tuple 
Swift :: func collectionview 
Swift :: swift how to dereference unsafemutablepointer 
Swift :: swift closures 
Swift :: xamarin get textview by id 
Swift :: Swift Create Multiple Objects of Class 
Swift :: cifilter image preserve orientation 
Ruby :: rails get current path 
ADD CONTENT
Topic
Content
Source link
Name
5+9 =