写了半天发现还没人家写的好,直接转载了iOS开发之为App设置正确的设计颜色html
若是在开发的过程当中发现Interface Builder
(包括xib和storyboard)设置的颜色运行后始终没法获得正确的显示,那么这个时候能够问一下公司的设计人员采用的是sRGB
、Adobe RGB
仍是Display P3
,而后在Interface Builder
设置对应的color profile
便可,通常为设计人员都采用sRGB
,故修改Interface Builder
中的color profile
为sRGB
。
同理代码也能够:ios
// 建立GenericRGB,与设备无关;Interface Builder中默认值 [UIColor colorWithCGColor:CGColorCreateGenericRGB(255.0/255.0, 85.0/255.0, 34.0/255.0, 1.0)]; // Apple RGB 等同于 sRGB [UIColor colorWithRed:255.0/255.0 green:85.0/255.0 blue:34.0/255.0 alpha:1.0]; // sRGB [UIColor colorWithCGColor:CGColorCreateSRGB(255.0/255.0, 85.0/255.0, 34.0/255.0, 1.0)]; // Diplay P3 [UIColor colorWithDisplayP3Red:255.0/255.0 green:85.0/255.0 blue:34.0/255.0 alpha:1.0]; // Adobe RGB // 这个是终极大法,全部的color profile均可以由这种方式编写 CGColorSpaceRef space = CGColorSpaceCreateWithName(kCGColorSpaceAdobeRGB1998); CGFloat components[] = {255.0/255.0, 85.0/255.0, 34.0/255.0, 1.0}; CGColorRef calibratedRGBColorRef = CGColorCreate(space, components); [UIColor colorWithCGColor:calibratedRGBColorRef];