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 guard let 
Swift :: Swift Swift continue statement with nested loops 
Swift :: iOS & Swift - The Complete iOS App Development Bootcamp 
Swift :: uitextview placeholder uikit ios 
Swift :: swift dictionary contains key 
Swift :: standard bank swift code 
Swift :: swift 5 get first character of string 
Swift :: concatenate string swift 
Swift :: swiftui change form section color 
Swift :: rounded ios button 
Swift :: swift create an empty array 
Swift :: Swift Switch Statement with Range 
Swift :: swift get file size from url 
Swift :: Swift Character Example 
Swift :: swiftui datepicker text color 
Swift :: swift subtract dates 
Swift :: how to loop in swift 
Swift :: Swift Expressions 
Swift :: Swift Closure as function parameter 
Swift :: Swift Weak Reference 
Swift :: Swift Array With Mixed Data Types 
Swift :: Swift static Property 
Swift :: Why Inheritance? 
Swift :: swiftui button only text tappable 
Swift :: Swift Find Number of Set Elements 
Swift :: swift string pad 
Swift :: Swift Function Overloading 
Swift :: vibrations in ios swift 
Ruby :: kill rails 
Ruby :: rails hidden field 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =