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.
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.
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.
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.
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.
See Apple's documentation: https://developer.apple.com/reference/uikit/uicolor/1621925-init
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With