美文网首页
iOS色彩空间——xib和代码设置颜色的偏差问题

iOS色彩空间——xib和代码设置颜色的偏差问题

作者: 武_IOS书 | 来源:发表于2018-10-20 09:38 被阅读0次

通过Xib设置样式如下:

image.png

通过代码设置如下:

NSInteger hexValue = 0x1ba9ba;
self.testView.backgroundColor = [UIColor colorWithRed:((float)((hexValue & 0xFF0000) >> 16)) / 255.0 
                                                  green:((float)((hexValue & 0xFF00) >> 8)) / 255.0 
                                                  blue:((float)(hexValue & 0xFF))/255.0 
                                                  alpha:1.0];

运行之后的结果:

很明显,上面视图与下面视图是有色彩偏差的。

或许此时,你需要查看下xib设置中,你选择的色彩空间标准是sRGB 或 Device RGB,如下:

image.png

解决方式:选择Generic RGB,运行后,你会发现两个视图的色彩就是一样的了,效果如下:


image.png

参考:http://stackoverflow.com/questions/10039641/ios-color-on-xcode-simulator-is-different-from-the-color-on-device#new-answer

相关文章

网友评论

      本文标题:iOS色彩空间——xib和代码设置颜色的偏差问题

      本文链接:https://www.haomeiwen.com/subject/fompzftx.html