[英]iOS: Colors defined in Interface Builder different from colors in Web View
We're building an iOS app which partly makes use of UIWebView
s to render some UI elements. 我们正在构建一个iOS应用程序,它部分利用
UIWebView
来呈现一些UI元素。 I noticed, that colors which are defined on the Storyboard are rendered differently than colors with the same values in the Web View. 我注意到,故事板上定义的颜色与Web视图中具有相同值的颜色的呈现方式不同。 The following screenshot shows three example colors on the storyboard and in the emulator:
#00C2F0
, #00843C
and #FF008F
. 以下屏幕截图显示了故事板和模拟器中的三种示例颜色:
#00C2F0
, #00843C
和#FF008F
。
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. 左方块显示在
UIWebView
呈现为CSS background-color
每种颜色,右方框直接通过Interface Builder显示指定为UIView
背景的颜色。
When I take a screenshot and measure the color values in Photoshop, the color shown within the UIWebView
is exactly as defined (ie exactly matching the hex color values given above), whereas the color shown through the UIView
is shifted. 当我在Photoshop中截取屏幕截图并测量颜色值时,
UIWebView
显示的颜色与定义完全一致(即完全匹配上面给出的十六进制颜色值),而通过UIView
显示的颜色会发生偏移。
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 (eg here or here ). 我在iOS上阅读了几篇关于“错误”颜色的帖子,这解释了由于色彩管理导致的这个“问题”,其目标是在所有设备上(例如此处或此处 )具有一致的视觉外观。 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
? 我可以做些什么来实现iOS原生视图和
UIWebView
呈现的颜色之间的匹配颜色?
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. 我终于解决了我的问题:原因不是我原先假设的
UIWebView
特定,而是由于事实上,通过Interface Builder分配的颜色在sRGB颜色空间中。 Changing to "Generic RGB" and then re-assigning the hex color values solved my issue. 更改为“Generic RGB” 然后重新分配十六进制颜色值解决了我的问题。
Very helpful was this question and answer (I feel the duplicate flag is unjustified). 非常有帮助的是这个问题和答案(我觉得重复的标志是不合理的)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.