{"id":19243587,"url":"https://github.com/devdragonli/lfldarkmodekit","last_synced_at":"2025-09-05T02:18:25.678Z","repository":{"id":56918412,"uuid":"261409202","full_name":"DevDragonLi/LFLDarkModeKit","owner":"DevDragonLi","description":"暗黑模式 iOS Dark Mode  Adapter Kit (Layer Color Auto Changed)","archived":false,"fork":false,"pushed_at":"2021-08-23T07:49:34.000Z","size":3174,"stargazers_count":12,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-13T07:47:24.471Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DevDragonLi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-05-05T09:10:36.000Z","updated_at":"2024-08-16T01:09:37.000Z","dependencies_parsed_at":"2022-08-21T04:50:52.852Z","dependency_job_id":null,"html_url":"https://github.com/DevDragonLi/LFLDarkModeKit","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevDragonLi%2FLFLDarkModeKit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevDragonLi%2FLFLDarkModeKit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevDragonLi%2FLFLDarkModeKit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevDragonLi%2FLFLDarkModeKit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DevDragonLi","download_url":"https://codeload.github.com/DevDragonLi/LFLDarkModeKit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250032380,"owners_count":21363828,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T17:18:42.606Z","updated_at":"2025-04-21T09:33:11.988Z","avatar_url":"https://github.com/DevDragonLi.png","language":"Objective-C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LFLDarkModeKit\n\n\u003e Adapter iOS DarkMode \n\n### 适配支持 **iOS 9.0+** 项目 \n\n###  Support:ObjC/Swift项目(纯OC/Swift/混编)均可使用\n\n- 对于iOS13+ 跟随系统暗黑开关\n\t- 也支持自定义APP内开关，设置即可【参考下文说明】\n- 对于iOS13以下，则默认Light模式\n\t- 也可以指定自定义模式，设置即可【参考下文说明】\n\n- 获取状态切换【模式切换检测】\n\n[![CI Status](https://img.shields.io/travis/DevdragonLi/LFLDarkModeKit.svg?style=flat)](https://travis-ci.org/DevdragonLi/LFLDarkModeKit)\n[![Version](https://img.shields.io/cocoapods/v/LFLDarkModeKit.svg?style=flat)](https://cocoapods.org/pods/LFLDarkModeKit)\n[![License](https://img.shields.io/cocoapods/l/LFLDarkModeKit.svg?style=flat)](https://cocoapods.org/pods/LFLDarkModeKit)\n[![Platform](https://img.shields.io/cocoapods/p/LFLDarkModeKit.svg?style=flat)](https://cocoapods.org/pods/LFLDarkModeKit)\n\n###  **[LFLDarkModeKit Detail](#use)** \n\n- CGColor并不会动态改变的解决方案\n- 常规项目的暗黑场景处理\n\n### **[Project Adapter By Apple API Description](#darkMode)** \n\n## Example\n\nTo run the example project, clone the repo, and run `pod install` from the \nExample directory first.\n\n## Installation\n\nLFLDarkModeKit is available through [CocoaPods](https://cocoapods.org). To install it, simply add the following line to your Podfile:\n\n```ruby\n\n  pod 'LFLDarkModeKit', '~\u003e 3.2.0'\n\n```\n\n## \u003ca name=\"use\"\u003e\u003c/a\u003e LFLDarkModeKit Detail\n\n- Layout Class   \n\n```\n.\n├── Core\n│   ├── LFLDarkModeManger.h\n│   ├── LFLDarkModeManger.m\n│   ├── UIColor+LFLDarkMode.h\n│   ├── UIColor+LFLDarkMode.m\n│   ├── UIView+LFLDarkMode.h\n│   └── UIView+LFLDarkMode.m\n├── LFLDarkModeKit.h\n└── Tool\n    ├── NSString+DarkModeKitBlank.h\n    └── NSString+DarkModeKitBlank.m\n    └── UIWindow+DarkModeKitKeyWondow.h\n    └── UIWindow+DarkModeKitKeyWondow.m\n  \n```\n\n### Project create bundle source \n\n\u003e **各项目自定义色值字符串映射对应颜色**\n\n- Example：@“PColor0” 在dark和light分别对应不同的真实色值一一映射，后续可支持新增模式\n\n- Example：darkModeAdapterColor.bundle （Color Set ）\n\t- dark.plist \n\t- light.plist\n\n### configDarkModeColorBundleURL \n\n```\n - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {\n\t NSURL *darkModeBundleURL = [[NSBundle mainBundle] URLForResource:@\"darkModeAdapterColor\" withExtension:@\"bundle\"];\n    [[LFLDarkModeManger sharedInstance] configDarkModeColorBundleURL:darkModeBundleURL];\n    return YES;\t\n}\n\n```\n\n###  用户自定义模式 【可不跟随系统开关】\n\n```\n\t  // 配置开启用户自定义开关模式\n    [LFLDarkModeManger.sharedInstance configUserDarkMode:YES];\n\n     // 获取当前用户自定义是否暗黑模式\n    [LFLDarkModeManger.sharedInstance isUserDarkMode];\n\n```\n\n###  获取状态切换【模式切换检测】\n\n```\n  \n  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_darkModeNoti:) name:LFLDarkModeChangeNotification object:nil];\n    \n- (void)_darkModeNoti:(NSNotification *)noti {\nNSDictionary *darkModeDic = noti.object;\nNSLog(@\"\\n通知：暗黑模式切换检测%@\",darkModeDic);\n}\n\n```\n\n###  Use Example  \n\n``` \n// view\nself.exampleLabel.textColor = [UIColor ColorAdpterWithHex:@\"DEMO\"];\n  \n// Imageview \nself.adapterImageView.image = [UIImage imageAdapterNamed:@\"exampleImage\"];\n\n// Layer \nself.customView.layerBorderColorHex = @\"DEMO\";\n\t    \n```\n\n## \u003ca name=\"darkMode\"\u003e\u003c/a\u003e Project Adapter By Apple API Description\n\n\u003e 全局关闭暗黑模式:在Info.plist文件中，添加UIUserInterfaceStyle key 名字为 User Interface Style 值为String，将UIUserInterfaceStyle key 的值设置为Light\n\n### images adapter\n\n- 如果项目中有需要适配暗黑模式的图片，可以在Assets.xcassets中设置，具体需要什么样式自己根据项目情况设置\n\t- any dark \n\t\n### UIColor\n\n- iOS13 API (当系统切换模式的时候，自动触发这两个方法来动态修改控件颜色)\n\n```\n\n+ (UIColor *)colorWithDynamicProvider:(UIColor * (^)(UITraitCollection *traitCollection))dynamicProvider API_AVAILABLE(ios(13.0), tvos(13.0)) API_UNAVAILABLE(watchOS);\n\n- (UIColor *)initWithDynamicProvider:(UIColor * (^)(UITraitCollection *traitCollection))dynamicProvider API_AVAILABLE(ios(13.0), tvos(13.0)) API_UNAVAILABLE(watchos);\n\n```\n\n### CGColor \n\n\u003e 设置的CGColor并不会动态改变,可以通过以下方案处理\n\n\u003e 如果适配CGColor，**一般需要各自自定义view实现此函数再处理，较为麻烦**。\n\n```\n\n- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {\n[super traitCollectionDidChange:previousTraitCollection];\n    \nif ([self.traitCollection hasDifferentColorAppearanceComparedToTraitCollection:previousTraitCollection]) {\n// Config  Color Adapter \n\t}\n}\n\n```\n- performAsCurrent\n\t\n```\n\n- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {\n[super traitCollectionDidChange:previousTraitCollection];\n [self.traitCollection performAsCurrentTraitCollection:^{\n    layer.backgroundColor = xxColor.CGColor;\n}];\n}\n\t\n```\n\n### VC Config Single Style \n \n```\nif (@available(iOS 13.0, *)) {\n    \n    [self setOverrideUserInterfaceStyle:UIUserInterfaceStyleDark];\n    \n} else {\n    \n}\n\n```\n\n### xib / Story \n\n- color set \n\t- any dark \n\t- [UIColor colorNamed:@\"customBlueColor\"] \n\n### NSAttributedString\n\n```\n NSDictionary * attributeDic = @{NSFontAttributeName:[UIFont systemFontOfSize:16],NSForegroundColorAttributeName:[UIColor xxColor]};\n\t\n```\n\n### UIActivityIndicatorView\n\n\n```\ntypedef NS_ENUM(NSInteger, UIActivityIndicatorViewStyle) {\n\t\n    UIActivityIndicatorViewStyleMedium,\n\t\n    UIActivityIndicatorViewStyleLarge,\n\t\n    UIActivityIndicatorViewStyleWhiteLarge API_DEPRECATED_WITH_REPLACEMENT(\"UIActivityIndicatorViewStyleLarge\",\n\t\n    UIActivityIndicatorViewStyleWhite API_DEPRECATED_WITH_REPLACEMENT(\"UIActivityIndicatorViewStyleMedium\",\n\t\n    UIActivityIndicatorViewStyleGray API_DEPRECATED_WITH_REPLACEMENT(\"UIActivityIndicatorViewStyleMedium\",\n\t\n};\n\t\n```\n\n### Life Style \n\n\n- UIView\n\n\t- traitCollectionDidChange(_:)\n\t- layoutSubviews()\n\t- draw(_:)\n\t- updateConstraints()\n\t- tintColorDidChange()\n\n- UIViewController\n\t- traitCollectionDidChange(_:)\n\t- updateViewConstraints()\n\t- viewWillLayoutSubviews()\n\t- viewDidLayoutSubviews()\n\n- UIPresentationController\n\t- traitCollectionDidChange(_:)\n\t- containerViewWillLayoutSubviews()\n\t- containerViewDidLayoutSubviews()\n\n## Author\n\n\u003e Dragonli_52171@163.com\n\n## License\n\nLFLDarkModeKit is available under the MIT license. See the LICENSE file for more info.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevdragonli%2Flfldarkmodekit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevdragonli%2Flfldarkmodekit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevdragonli%2Flfldarkmodekit/lists"}