4.如何在xib中正确设置颜色

4.如何在xib中正确设置颜色

写了半天发现还没人家写的好,直接转载了iOS开发之为App设置正确的设计颜色

简单总结一下

如果在开发的过程中发现Interface Builder(包括xib和storyboard)设置的颜色运行后始终无法得到正确的显示,那么这个时候可以问一下公司的设计人员采用的是sRGBAdobe RGB还是Display P3,然后在Interface Builder设置对应的color profile即可,一般为设计人员都采用sRGB,故修改Interface Builder中的color profilesRGB
设置color profile
同理代码也可以:

// 创建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];

posted @ 2020-12-02 22:01  小小个子大个头  阅读(595)  评论(0编辑  收藏  举报