Can't convert RGB to UIColor

I am trying to convert rgb color to UIColor using a function I found, but it cannot give me the correct color. Why am I getting completely wrong color from the one in Photoshop?

Here's an illustration:

enter image description here

The color from the photoshop file is as follows: 009d13

UINavigationBar.appearance().barTintColor = UIColorFromRGB(009e13)

      

Function

func UIColorFromRGB(rgbValue: UInt) -> UIColor {
    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)
    )
}

      

+3


source to share


1 answer


If you have a hex color code, your best bet is to use uicolor + hex lib. https://github.com/kevinrenskers/UIColor-HexString

For quick



https://github.com/yeahdongcn/UIColor-Hex-Swift

+1


source







All Articles