JYDarkModeKit is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'JYDarkModeKit'
导入头文件
#import "JYDarkModeKit.h"
在AppDelegate
进行初始化工作
JYEnvironmentConfiguration * configuration = [JYEnvironmentConfiguration
initWithThemeChangeHandler:^{
NSLog(@"themeChangeHandler");
}];
[JYTraitCollection setupEnvironmentWithConfiguration:configuration];
[JYTraitCollection registerWithApplication:application animated:YES];
设置背景颜色
self.view.backgroundColor = [UIColor jy_colorWithLightColor:[UIColor yellowColor] darkColor:[UIColor orangeColor]];
设置图片
UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(50, 550, 100, 50)];
[imageView setImage:[UIImage jy_imageWithLightImage:[UIImage imageNamed:@"test3"] darkImage:[UIImage imageNamed:@"test"]]];
修改颜色
///普通模式
[JYTraitCollection setOverrideTraitCollectionStyle:JYInterfaceStyleLight animated:YES];
///夜间模式
[JYTraitCollection setOverrideTraitCollectionStyle:JYInterfaceStyleDark animated:YES];
获取当前样式
///iOS13以上通过
[JYTraitCollection currentTraitCollection].uiTraitCollection.userInterfaceStyle
///iOS13以下
JYTraitCollection.overrideTraitCollection.userInterfaceStyle
JY
JYDarkModeKit is available under the MIT license. See the LICENSE file for more info.