1.顏色的適配
問題:
iOS13下公司App某些頁面顯示情況:
0.暗黑.png
這是在暗黑模式下顯示的情況肉渴,出現(xiàn)這種情況是因為該頁面的tableview和Cell都沒有設(shè)置背景色裹匙,導(dǎo)致系統(tǒng)自動按照系統(tǒng)的顯示外觀對頁面顏色進行了設(shè)置。
禁用App的暗黑模式
由于我們沒有對iOS13新增的暗黑模式進行適配,我們可以禁用App的暗黑模式丽啡。
在info.plist文件中增加User Interface Style并設(shè)置為Light梁肿。
0.禁用.png
禁用App某些頁面的暗黑模式
如果我們對App某些頁面適配了暗黑模式,有些頁面還沒來得及適配徐许,我們可以對某些頁面禁用暗黑模式。
self.view.overrideUserInterfaceStyle=UIUserInterfaceStyleLight;
適配顏色
iOS13設(shè)置顏色增加了方法
/* Create a dynamic color with a provider.
* When methods are called on this color that need color component values,
* the provider is called with UITraitCollection.currentTraitCollection.
* The provider should use that trait collection to decide a more fundamental UIColor to return.
* As much as possible, use the given trait collection to make that decision, not other state.
*/+(UIColor *)colorWithDynamicProvider:(UIColor *(^)(UITraitCollection? ? *traitCollection))dynamicProvider API_AVAILABLE(ios(13.0),tvos(13.0))API_UNAVAILABLE(watchos);-(UIColor *)initWithDynamicProvider:(UIColor *(^)(UITraitCollection *traitCollection))dynamicProvider API_AVAILABLE(ios(13.0),tvos(13.0))API_UNAVAILABLE(watchos);
我們可以通過block回調(diào)判斷當(dāng)前的模式卒蘸,然后設(shè)置不同模式下的顏色雌隅。
// 顏色適配if(@available(iOS13.0,*)){self.view.backgroundColor=[UIColor colorWithDynamicProvider:^UIColor*_Nonnull(UITraitCollection*_Nonnull traitCollection){if(traitCollection.userInterfaceStyle==UIUserInterfaceStyleDark){return[UIColor blackColor];// 暗黑模式下的顏色}else{return[UIColor whiteColor];// 非暗黑模式下的顏色}}];}
UIUserInterfaceStyle是一個枚舉,有暗黑模式和淺色模式缸沃。
typedefNS_ENUM(NSInteger,UIUserInterfaceStyle){UIUserInterfaceStyleUnspecified,UIUserInterfaceStyleLight,UIUserInterfaceStyleDark,}API_AVAILABLE(tvos(10.0))API_AVAILABLE(ios(12.0))API_UNAVAILABLE(watchos);
2.圖片的適配
0.圖片.png
我們可以選擇Appearances為Any恰起,Dark,這樣就會出現(xiàn)兩組圖片趾牧,我們可以設(shè)置暗黑模式下的圖片和非暗黑模式下的圖片
作者:梁森的簡書
鏈接:http://www.reibang.com/p/ab2a84e87807
來源:簡書
著作權(quán)歸作者所有检盼。商業(yè)轉(zhuǎn)載請聯(lián)系作者獲得授權(quán),非商業(yè)轉(zhuǎn)載請注明出處武氓。