{"id":908,"url":"https://github.com/Draveness/DKNightVersion","last_synced_at":"2025-07-30T19:33:07.578Z","repository":{"id":30373146,"uuid":"33925743","full_name":"draveness/DKNightVersion","owner":"draveness","description":"Manage Colors, Integrate Night/Multiple Themes. (Unmaintained)","archived":true,"fork":false,"pushed_at":"2019-09-03T10:59:06.000Z","size":10206,"stargazers_count":3553,"open_issues_count":36,"forks_count":516,"subscribers_count":91,"default_branch":"master","last_synced_at":"2024-10-29T15:47:43.405Z","etag":null,"topics":["cocoapods","colors","dknightversion","mode","night-mode","objective-c","theme"],"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/draveness.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-04-14T10:32:43.000Z","updated_at":"2024-10-25T16:16:46.000Z","dependencies_parsed_at":"2022-09-02T13:41:22.370Z","dependency_job_id":null,"html_url":"https://github.com/draveness/DKNightVersion","commit_stats":null,"previous_names":[],"tags_count":47,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/draveness%2FDKNightVersion","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/draveness%2FDKNightVersion/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/draveness%2FDKNightVersion/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/draveness%2FDKNightVersion/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/draveness","download_url":"https://codeload.github.com/draveness/DKNightVersion/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227590121,"owners_count":17790446,"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":["cocoapods","colors","dknightversion","mode","night-mode","objective-c","theme"],"created_at":"2024-01-05T20:15:34.399Z","updated_at":"2024-12-04T19:32:26.756Z","avatar_url":"https://github.com/draveness.png","language":"Objective-C","readme":"\n![](./images/Banner.png)\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://img.shields.io/badge/Language-%20Objective--C%20-orange.svg\"\u003e\u003cimg src=\"https://img.shields.io/badge/Language-%20Objective--C%20-orange.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"http://cocoadocs.org/docsets/DKNightVersion\"\u003e\u003cimg src=\"http://img.shields.io/cocoapods/v/DKNightVersion.svg?style=flat\"\u003e\u003c/a\u003e\n\u003ca href=\"https://travis-ci.org/Draveness/DKNightVersion\"\u003e\u003cimg src=\"https://travis-ci.org/Draveness/DKNightVersion.png\"\u003e\u003c/a\u003e\n\u003cimg src=\"https://img.shields.io/badge/license-MIT-blue.svg\"\u003e\n\u003ca href=\"https://img.shields.io/badge/platform-%20iOS%20-lightgrey.svg\"\u003e\u003cimg src=\"https://img.shields.io/badge/platform-%20iOS%20-lightgrey.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/Carthage/Carthage\"\u003e\u003cimg src=\"https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n- [x] Easily integrate and high performance\n- [x] Providing UIKit and CoreAnimation category\n- [x] Read colour customisation from file\n- [x] Support different themes\n- [x] Generate picker for other libs with one line macro\n\n\n# Demo\n\n\u003cp align='center'\u003e\n  \u003cimg src=\"./images/DKNightVersion.gif\"\u003e\n\u003c/p\u003e\n\n----\n\n+ [Installation with CocoaPods](#Installation-with-CocoaPods)\n    + [Podfile](#podfile)\n    + [Import](#import)\n+ [Usage](#usage)\n+ [Advanced Usage](#advanced-usage)\n    + [DKNightVersionManger](#dknightversionmanager)\n        + [Change Theme](#change-theme)\n        + [Post Notification](#post-notification)\n    + [DKColorPicker](#dkColorpicker)\n    + [DKColorTable](#dkcolortable)\n    + [pickerify](#pickerify)\n    + [Create temporary DKColorPicker](#create-temporary-dkcolorpicker)\n    + [DKImagePicker](#dkimagepicker)\n\n\u003e If you want to implement night mode in Swift project without import Objective-C code. [NightNight](https://github.com/Draveness/NightNight)\n is the Swift version which does the same work.\n\n# How To Get Started\n\nDKNightVersion supports multiple methods for installing the library in a project.\n\n## Installation with CocoaPods\n\n[CocoaPods](https://cocoapods.org/) is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries like DKNightVersion in your projects. See the [Get Started section](https://cocoapods.org/#get_started) for more details.\n\n### Podfile\n\nTo integrate DKNightVersion into your Xcode project using CocoaPods, specify it in your `Podfile`:\n\n```shell\npod \"DKNightVersion\"\n```\n\nThen, run the following command:\n\n```shell\n$ pod install\n```\n\n\n### Import\n\nImport DKNightVersion header file\n\n```objectivec\n#import \u003cDKNightVersion/DKNightVersion.h\u003e\n```\n\n## Usage\n\nCheckout `DKColorTable.txt` file in your project, which locates in `Pods/DKNightVersion/Resources/DKNightVersion.txt`.\n```\nNORMAL   NIGHT\n#ffffff  #343434 BG\n#aaaaaa  #313131 SEP\n```\n\n\u003e You can also create another colour table file, and specify it with [DKColorTable](#dkcolortable).\n\nA, set color picker like this with `DKColorPickerWithKey`, which generates a DKColorPicker block\n\n```objectivec\nself.view.dk_backgroundColorPicker = DKColorPickerWithKey(BG);\n```\n\nAfter the current theme version change to `DKThemeVersionNight`, the view background colour would switch to `#343434`.\n\n```objectivec\n[DKNightVersionManager nightFalling];\n``` \n\nAlternatively, you could change the theme version by manager's property `themeVersion` which is a string\n\n```objectivec\nDKNightVersionManager *manager = [DKNightVersionManager sharedInstance];\nmanager.themeVersion = DKThemeVersionNormal;\n```\n\n## Advanced Usage\n\nThere are two approaches you can use to integrate night mode to your iOS App.\n\n### DKNightVersionManager\n\nThe latest version for DKNightVersion add a readonly `dk_manager` property for `NSObject` returns the `DKNightVersionManager` singleton.\n\n#### Change Theme\n\nYou can call `nightFalling` or `dawnComing` to switch the current theme version to `DKThemeVersionNight` or `DKThemeVersionNormal`.\n\n```objectivec\n[self.dk_manager dawnComing];\n[self.dk_manager nightFalling];\n```\n\nModify `themeVersion` property to switch the theme version directly.\n\n```objectivec\nself.dk_manager.themeVersion = DKThemeVersionNormal;\nself.dk_manager.themeVersion = DKThemeVersionNight;\n// if there is a RED column in DKColorTable.txt (default) or in \n// other `file` if you customize `file` property for `DKColorTable`\nself.dk_manager.themeVersion = @\"RED\"; \n```\n\n#### Post Notification\n\nEvery time the current theme version changes, `DKNightVersionManager` would post a `DKNightVersionThemeChangingNotification`. If you want to do some customisation, you can observe this notification and react with proper actions.\n\n### DKColorPicker\n\n`DKColorPicker` is the core of DKNightVersion. And this lib adds dk_colorPicker to every UIKit and Core Animation components. Ex:\n\n```objectivec\n@property (nonatomic, copy, setter = dk_setBackgroundColorPicker:) DKColorPicker dk_backgroundColorPicker;\n@property (nonatomic, copy, setter = dk_setTintColorPicker:) DKColorPicker dk_tintColorPicker;\n```\n\nDKColorPicker is defined in `DKColor.h` file receives a `DKThemeVersion` as the parameter and returns a `UIColor`.\n\n```objectivec\ntypedef UIColor *(^DKColorPicker)(DKThemeVersion *themeVersion);\n```\n\n+ Use `DKColorPickerWithKey(key)` to obtain `DKColorPicker` from `DKColorTable`\n\n    ```objectivec\n    view.dk_backgroundColorPicker = DKColorPickerWithKey(BG);\n    ```\n\n+ Use `DKColorPickerWithRGB` to generate a `DKColorPicker`\n\n    ```objectivec\n    view.dk_backgroundColorPicker =  DKColorPickerWithRGB(0xffffff, 0x343434);\n    ```\n\n### DKColorTable\n\n`DKColorTable` is a new feature in DKNightVersion which providing us with an elegant way to manage colour setting in a project. Use as follows:\n\nThere is a file called `DKColorTable.txt`\n\n```\nNORMAL   NIGHT\n#ffffff  #343434 BG\n#aaaaaa  #313131 SEP\n```\n\nThe first line of this file indicated different themes. **NORMAL is required column**, and others are optional. So if you don't need to integrate different themes in your app, leave the first column in this file, like this:\n\n```\nNORMAL\n#ffffff BG\n#aaaaaa SEP\n```\n\n`NORMAL` and `NIGHT` are two different themes, `NORMAL` is the default and for normal mode. `NIGHT` is optional and for night mode.\n\nYou can add multiple columns in this `DKColorTable.txt` file as many as you want.\n\n```\nNORMAL   NIGHT    RED\n#ffffff  #343434  #ff0000 BG\n#aaaaaa  #313131  #ff0000 SEP\n```\n\nThe last column is the key for a colour entry, DKNightVersion uses the current `themeVersion` (ex: `NORMAL` `NIGHT` and `RED`) and key (ex: `BG`, `SEP`) to find the corresponding colour in DKColorTable.\n\n`DKColorTable` has a property `file`, it will loads the color setting in this `file` when `+ [DKColorTable sharedColorTable` is called. Default value of `file` is `DKColorTable.txt`.\n\n```objectivec\n@property (nonatomic, strong) NSString *file;\n```\n\nYou can also add another file into your project and fill your colour setting in that file.\n\n```\n// color.txt\nNORMAL   NIGHT\n#ffffff  #343434 BG\n```\n\nAlso, do not forget to change the `file` property of the colour table.\n\n```objectivec\n[DKColorTable sharedColorTable].file = @\"color.txt\"\n```\n\nThe code above would reload colour setting from `color.txt` file.\n\n### Create temporary DKColorPicker\n\nIf you'd want to create some temporary DKColorPicker, you can use these methods.\n\n```objectivec\nview.dk_backgroundColorPicker =  DKColorPickerWithRGB(0xffffff, 0x343434);\n```\n\n`DKColorPickerWithRGB` will return a DKColorPicker which set background color to `#ffffff` when current theme version is `DKThemeVersionNormal` and `#343434` when it is `DKThemeVersionNight`.\n\nThere are also some similar functions like `DKColorPickerWithColors`\n\n```objectivec\nDKColorPicker DKColorPickerWithRGB(NSUInteger normal, ...);\nDKColorPicker DKColorPickerWithColors(UIColor *normalColor, ...);\n```\n\n`DKColor` also provides a cluster of convenient `API` which returns `DKColorPicker` block, these blocks **return the same colour in different themes**.\n\n```objectivec\n+ (DKColorPicker)colorPickerWithUIColor:(UIColor *)color;\n\n+ (DKColorPicker)colorPickerWithWhite:(CGFloat)white alpha:(CGFloat)alpha;\n+ (DKColorPicker)colorPickerWithHue:(CGFloat)hue saturation:(CGFloat)saturation brightness:(CGFloat)brightness alpha:(CGFloat)alpha;\n+ (DKColorPicker)colorPickerWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha;\n+ (DKColorPicker)colorPickerWithCGColor:(CGColorRef)cgColor;\n+ (DKColorPicker)colorPickerWithPatternImage:(UIImage *)image;\n#if __has_include(\u003cCoreImage/CoreImage.h\u003e)\n+ (DKColorPicker)colorPickerWithCIColor:(CIColor *)ciColor NS_AVAILABLE_IOS(5_0);\n#endif\n\n+ (DKColorPicker)blackColor;\n+ (DKColorPicker)darkGrayColor;\n+ (DKColorPicker)lightGrayColor;\n+ (DKColorPicker)whiteColor;\n+ (DKColorPicker)grayColor;\n+ (DKColorPicker)redColor;\n+ (DKColorPicker)greenColor;\n+ (DKColorPicker)blueColor;\n+ (DKColorPicker)cyanColor;\n+ (DKColorPicker)yellowColor;\n+ (DKColorPicker)magentaColor;\n+ (DKColorPicker)orangeColor;\n+ (DKColorPicker)purpleColor;\n+ (DKColorPicker)brownColor;\n+ (DKColorPicker)clearColor;\n```\n\n### pickerify\n\nDKNightVersion provides a powerful feature which can generate dk_xxxColorPicker with a macro called `pickerify`.\n\n```objectivec\n@pickerify(TableViewCell, cellTintColor)\n```\n\nIt automatically generates `dk_cellTintColorPicker` for you.\n\n\n### DKImagePicker\n\nUse `DKImagePicker` to change images when `manager.themeVersion` changes.\n\n```objectivec\nimageView.dk_imagePicker = DKImagePickerWithNames(@\"normal\", @\"night\");\n```\n\nThe first argument passed into the function is used for `NORMAL` theme, and the second is used for `NIGHT` theme, the themes order is determined by the configuration in \nDKColorTable.txt file which is NORMAL and NIGHT.\n\nIf your file like this:\n\n```\nNORMAL   NIGHT    RED\n#ffffff  #343434  #fafafa BG\n#aaaaaa  #313131  #aaaaaa SEP\n#0000ff  #ffffff  #fa0000 TINT\n#000000  #ffffff  #000000 TEXT\n#ffffff  #444444  #ffffff BAR\n```\n\nSet your image picker in this order:\n\n```objectivec\nimageView.dk_imagePicker = DKImagePickerWithNames(@\"normal\", @\"night\", @\"red\");\n```\n\nThe order of images or names is the same in DKColorTable.txt file.\n\n```objectivec\nDKImagePicker DKImagePickerWithImages(UIImage *normalImage, ...);\nDKImagePicker DKImagePickerWithNames(NSString *normalName, ...);\n```\n\n# Contribute\n\nFeel free to open an issue or pull request, if you need help or there is a bug.\n\n# Contact\n\n- Powered by [Draveness](http://github.com/draveness)\n- Personal website [Draveness](http://draveness.me)\n\n# Todo\n\n- Documentation\n\n# License\n\nDKNightVersion is available under the MIT license. See the LICENSE file for more info.\n\nThe MIT License (MIT)\n\nCopyright (c) 2015 Draveness\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","funding_links":[],"categories":["Color"],"sub_categories":["Linter","Other free courses"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDraveness%2FDKNightVersion","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FDraveness%2FDKNightVersion","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDraveness%2FDKNightVersion/lists"}