Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS: Colors defined in Interface Builder different from colors in Web View

We're building an iOS app which partly makes use of UIWebViews to render some UI elements. I noticed, that colors which are defined on the Storyboard are rendered differently than colors with the same values in the Web View. The following screenshot shows three example colors on the storyboard and in the emulator: #00C2F0, #00843C and #FF008F.

shifted colors Interface Builder and Emulator

The left squares show each color rendered as CSS background-color within a UIWebView, the right square shows the color assigned as background to a UIView directly through Interface Builder.

When I take a screenshot and measure the color values in Photoshop, the color shown within the UIWebView is exactly as defined (i.e. exactly matching the hex color values given above), whereas the color shown through the UIView is shifted.

I've read several posts about "wrong" colors on iOS, which explain this "issue" due to color management with the goal to have a consistent visual appearance on all devices (e.g. here or here). While this sounds totally reasonable, it does not explain the inconsistent rendering through different controls.

Is there anything I can do to achieve matching colors between iOS native views and colors rendered within a UIWebView?

like image 217
qqilihq Avatar asked Oct 26 '15 10:10

qqilihq


1 Answers

I finally solved my issue: The reason was not UIWebView-specific as I had originally assumed, but caused by the fact, that the colors assigned through Interface Builder were in sRGB color space. Changing to "Generic RGB" and then re-assigning the hex color values solved my issue.

color picker color space

Very helpful was this question and answer (I feel the duplicate flag is unjustified).

like image 182
qqilihq Avatar answered Oct 29 '22 11:10

qqilihq