故事板中的颜色与 UIColor 不匹配 [英] Color in storyboard not matching UIColor

查看:44
本文介绍了故事板中的颜色与 UIColor 不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将代码中的颜色定义为

I am defining a color in code as

[UIColor colorWithHue:32.0/360.0 saturation:0.88 brightness:0.97 alpha:1]

如果我尝试在情节提要中设置相同的颜色,则在运行应用程序时,它的颜色与代码中定义的颜色略有不同.如果我将颜色拖到上颚然后选择不同的颜色并再次选择上颚,HSB 值会略有不同.它似乎在界面构建器中捕捉到不同的(RGB?)颜色.

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.

推荐答案

Xcode 8+, iOS 10+

我最近遇到了这个问题,但发布的答案都没有.事实证明,随着 iOS 10 SDK 的发布,UIColor 初始值设定项 init(red:green:blue:alpha:) 现在使用扩展的 sRGB 范围,因此您有在 Storyboard 上配置颜色值时进行相应设置.

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.

请参阅 Apple 的文档:https://developer.apple.com/reference/uikit/uicolor/1621925-初始化

See Apple's documentation: https://developer.apple.com/reference/uikit/uicolor/1621925-init

这篇关于故事板中的颜色与 UIColor 不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆