Color in storyboard not matching UIColor

Nick picture Nick · Feb 6, 2015 · Viewed 16.4k times · Source

I am defining a color in code as

[UIColor colorWithHue:32.0/360.0 saturation:0.88 brightness:0.97 alpha:1]

If I try to set the same color in storyboard, when running the App it is a slightly different colour to the one defined in code. If I drag the color to the palate then select a different color and select the palate one again, the HSB values are slightly different. It seems it is snapping to a different (RGB?) color in interface builder.

Answer

camilomq picture camilomq · Oct 15, 2016

Xcode 8+, iOS 10+

I recently faced this problem and none of the posted answers did it. It turns out that with the release of iOS 10 SDK, the UIColor initializer init(red:green:blue:alpha:) now uses the extended sRGB range, so you have to set accordingly when configuring your color values on the Storyboard.

enter image description here

See Apple's documentation: https://developer.apple.com/reference/uikit/uicolor/1621925-init