4.如何在xib中正確設定顏色
阿新 • • 發佈:2020-12-02
寫了半天發現還沒人家寫的好,直接轉載了iOS開發之為App設定正確的設計顏色
簡單總結一下
如果在開發的過程中發現Interface Builder
(包括xib和storyboard)設定的顏色執行後始終無法得到正確的顯示,那麼這個時候可以問一下公司的設計人員採用的sRGB
、Adobe RGB
還是Display P3
,然在Interface Builder
設定對應的color profile
即可,一般為設計人員都採用sRGB
,故修改Interface Builder
中的color profile
為sRGB
。
同理程式碼也可以:
// 建立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];