Search
 
SCRIPT & CODE EXAMPLE
 

SWIFT

swift UIColor to String

extension UIColor {
    var rgbComponents:(red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) {
        var r:CGFloat = 0
        var g:CGFloat = 0
        var b:CGFloat = 0
        var a:CGFloat = 0
        if getRed(&r, green: &g, blue: &b, alpha: &a) {
            return (r,g,b,a)
        }
        return (0,0,0,0)
    }
    // hue, saturation, brightness and alpha components from UIColor**
    var hsbComponents:(hue: CGFloat, saturation: CGFloat, brightness: CGFloat, alpha: CGFloat) {
        var hue:CGFloat = 0
        var saturation:CGFloat = 0
        var brightness:CGFloat = 0
        var alpha:CGFloat = 0
        if getHue(&hue, saturation: &saturation, brightness: &brightness, alpha: &alpha){
            return (hue,saturation,brightness,alpha)
        }
        return (0,0,0,0)
    }
    var htmlRGBColor:String {
        return String(format: "#%02x%02x%02x", Int(rgbComponents.red * 255), Int(rgbComponents.green * 255),Int(rgbComponents.blue * 255))
    }
    var htmlRGBaColor:String {
        return String(format: "#%02x%02x%02x%02x", Int(rgbComponents.red * 255), Int(rgbComponents.green * 255),Int(rgbComponents.blue * 255),Int(rgbComponents.alpha * 255) )
    }
}
Comment

PREVIOUS NEXT
Code Example
Swift :: map vs compactmap in swiftui 
Swift :: Swift Function overloading with Argument Label 
Swift :: swift hmac256 
Swift :: on edit input field provide default value if textfield get empty swift 
Swift :: Swift Print Variables and Strings together 
Swift :: Swift Escape Sequences 
Swift :: how to get list of value from specific keys in array object in swift 
Swift :: Declare Constants in Swift 
Swift :: do something when your HTTP response finishes. swift 
Swift :: uilabel font size and bold 
Swift :: swift ease in out animatekeyframes 
Swift :: swift 5 full screen image viewer 
Swift :: key path expression as functions ios swift 
Swift :: Swift repeat...while Loop 
Swift :: So, because promart depends on both flutter_test from sdk and freezed ^1.1.1, version solving failed. [ ] FINE: Exception type: SolveFailure 
Swift :: enum Associated Values Swift 
Swift :: swift hashable 
Ruby :: rails delete child on parent delete 
Ruby :: ruby select first n elements from array 
Ruby :: get current year in ruby 
Ruby :: ruby gem dir 
Ruby :: ruby generate random number 
Ruby :: ruby each_with_object 
Ruby :: ruby unshift method 
Ruby :: ruby create csv 
Ruby :: rails undo generate model 
Ruby :: ruby latest version 
Ruby :: heroku run rails c 
Ruby :: string to hash ruby 
Ruby :: ruby on rails binding.pry 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =