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

2018-10-20  本文已影响0人  武_IOS书

通过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

上一篇 下一篇

猜你喜欢

热点阅读