Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Color in storyboard not matching UIColor

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.

like image 761
Nick Avatar asked Feb 06 '15 14:02

Nick


People also ask

How do you add a custom color to a storyboard?

Open your asset catalog, click the + and add a color set. Click on the color that was created and you can name it and set the color using the inspector. Thereafter that color shows up in storyboard color chooses in the area called Named Colors.

How do you change the background color on a storyboard?

First let us see using storyboard, Open Main. storyboard and add one view to the View Controller. On the right pane you can see the property, and from there update the background color to color you want your view to be as show below.

Is storyboard or SwiftUI better?

For most new developers coding on iOS 13 or higher, you should learn SwiftUI. If you need to maintain an older code base with Storyboards, you should learn Storyboards.


1 Answers

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

like image 139
camilomq Avatar answered Sep 20 '22 05:09

camilomq