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.
4 Solutions Collect From Internet About “Color in storyboard not matching UIColor”
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
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
I had the same issue. I was seeing runtime RGB values of the colors from storyboards not matching UIColors created at runtime in code. I was able to fix this in storyboards by setting the color to be “Generic RGB” (vs the default of sRGB) when configuring it. Here is a screenshot of what I’m talking about in IB:
Seems this is a bug. When logging the color set by IB in code, it has the values H:27.982594 S:0.899257 B:0.953253
I have filed a bug report to Apple: rdar://19744216
Thanks to Zaph
CGFloat cols; [color getHue:&cols saturation:&cols brightness:&cols alpha:&cols]; NSLog(@"H:%f S:%f B:%f %f",cols*360, cols, cols, cols);
In my case what was exactly accurate was Color LCD:
I hope I’ve helped 😀
- Reachability takes too long to fail when connected to WIFI without internet
- Why did my app get rejected because “Multitasking apps may only use background”?
- Problems with SSL Pinning and AFNetworking 2.5.0 (NSURLErrorDomain error -1012.)
- How can I load a local HTML file into the UIWebView?
- Limit a double to two decimal places without trailing zeros
- –resource-rules has been deprecated in mac os x >= 10.10
- Replace string with regex in swift
- Upload pdf file (from document directory) through web service in iPhone?
- NSOperation on the iPhone
- Programmatically Create Aggregate Audio Devices In Swift Using CoreAudio
- iPhone4S with iOS6 AVAudioPlayer is working, but no sound
- NSImageView double click action
- Make a two-digit string from a single-digit integer
- Passing variables to an applescript
- How would I be able to open google maps when I press a button in my app?