轻量级的 iOS 框架,用于将夜间模式添加到项目中
pod 'AJRNight', :git => 'https://github.com/AmarJayR/AJRNight.git'
克隆项目,并将 AJRNight 目录中的文件添加到您的项目中
AJRNight 非常轻量、灵活且易于使用。本质上,幕后的操作是我们在 UIView
中添加一个新的分类 nightProperties
。这个字典包含所有需要更改的属性以便启用夜间模式(如 backgroundColor
、textColor
等。)
将以下行添加到任何需要夜间模式的视图控制器中
#import <AJRNight/AJRNight.h>
将 AJRNightDelegate
代理添加到您的视图控制器
@interface PreferencesViewController : UIViewController <AJRNightDelegate>
在您的 viewDidLoad 中添加以下内容
[[AJRNight sharedClient] addViewController:self];
编辑需要更改的任何 UIView
的 nightProperties
。 -注意:通过 appearance
([[UILabel appearance] setNightProperties:@{}
)设置夜间属性在大多数但不是所有 UIView 中受支持
self.view.nightProperties = @{ @"backgroundColor": UIColorFromRGB(0x343338) };
[[UILabel appearance] setNightProperties:@{ @"textColor": [UIColor whiteColor] }];
当您想要切换到夜间模式时,只需调用 [[AJRNight sharedClient] setNightMode:YES];
包含更多详细信息的示例项目已提供。