{"id":28673226,"url":"https://github.com/rayjiang16/xycolor","last_synced_at":"2025-06-13T20:09:09.262Z","repository":{"id":56928580,"uuid":"198124513","full_name":"RayJiang16/XYColor","owner":"RayJiang16","description":"An easy way to adapter dark mode on CALayer. iOS 快速适配夜间模式","archived":false,"fork":false,"pushed_at":"2020-02-07T02:58:12.000Z","size":52,"stargazers_count":80,"open_issues_count":1,"forks_count":8,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-13T20:09:08.021Z","etag":null,"topics":["color","darkmode","swift5"],"latest_commit_sha":null,"homepage":"","language":"Swift","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/RayJiang16.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":"2019-07-22T01:27:50.000Z","updated_at":"2025-02-06T12:02:11.000Z","dependencies_parsed_at":"2022-08-20T23:30:44.657Z","dependency_job_id":null,"html_url":"https://github.com/RayJiang16/XYColor","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/RayJiang16/XYColor","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RayJiang16%2FXYColor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RayJiang16%2FXYColor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RayJiang16%2FXYColor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RayJiang16%2FXYColor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RayJiang16","download_url":"https://codeload.github.com/RayJiang16/XYColor/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RayJiang16%2FXYColor/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259712417,"owners_count":22900041,"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":["color","darkmode","swift5"],"created_at":"2025-06-13T20:09:03.182Z","updated_at":"2025-06-13T20:09:09.247Z","avatar_url":"https://github.com/RayJiang16.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# XYColor\n\n[![GitHub Actions](https://github.com/RayJiang16/XYColor/workflows/build/badge.svg?branch=master)](https://github.com/RayJiang16/XYColor/actions?query=workflow%3Abuild)\n[![CocoaPods Compatible](https://img.shields.io/cocoapods/v/XYColor.svg)](https://cocoapods.org/pods/XYColor)\n[![Carthage Compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n[![Platform](https://img.shields.io/cocoapods/p/XYColor.svg?style=flat)](./)\n[![License](https://img.shields.io/cocoapods/l/XYColor.svg?style=flat)](./LICENSE)\n\nAn easy way to adapter dark mode on CALayer\n\n[中文介绍](README_CN.md)\n\n## Requirements\n\n- iOS 8.0+\n- Swift 5.0+\n- Xcode 11.0+\n\n## Installation\n\n**Installation with [CocoaPods](https://cocoapods.org/):**\n- Swift\n```\npod 'XYColor'\n```\n- Objective-C\n```\npod 'XYColorOC'\n```\n\n**Installation with [Carthage](https://github.com/Carthage/Carthage):**\n```\ngithub \"RayJiang16/XYColor\"\n```\nRun `carthage` to build the frameworks and drag the appropriate framework (`XYColor.framework` or `XYColorOC.framework`) into your Xcode project based on your need. Make sure to add only one framework and not both.\n\n\n## Usage\nAs we all known `UIViewController` and `UIView` has `traitCollection.userInterfaceStyle` property, but `CALayer` doesn't.\nTherefor `CALayer` wants to adapter dark mode, it need to bind on a `UIView`.\nThat means `CALayer` will change color when `UIView.traitCollection.userInterfaceStyle` changed.\n\n**Swift**\n```swift\nimport XYColor\n\n// View\nprivate var customView: UIView = {\n    let view = UIView()\n    ...\n    view.setLayerBorderColor(UIColor.label)\n    view.setLayerShadowColor(UIColor.label)\n    view.setLayerBackgroundColor(UIColor.systemBackground)\n    ...\n    return view\n}()\n\n// Layer\nprivate var customLayer: CALayer = {\n    let layer = CALayer()\n    ...\n    layer.setBorderColor(UIColor.label, with: customView)\n    layer.setShadowColor(UIColor.label, with: customView)\n    layer.setBackgroundColor(UIColor.systemBackground, with: customView)\n    ...\n    return layer\n}()\n\n// Create color\nprivate var color: UIColor = {\n    return UIColor.create(light: .black, dark: .white)\n}()\n```\n\n**Objective-C**\n```objective-c\n#import \"XYColorOC/XYColorOC.h\"\n\n// View\n- (UIView *)customView {\n    ...\n    [_customView xy_setLayerBorderColor:UIColor.labelColor];\n    [_customView xy_setLayerShadowColor:UIColor.labelColor];\n    [_customView xy_setLayerBackgroundColor:UIColor.systemBackgroundColor];\n    ...\n}\n\n// Layer\n- (CALayer *)customLayer {\n    ...\n    [_customLayer xy_setLayerBorderColor:UIColor.labelColor with:self.customView];\n    [_customLayer xy_setLayerShadowColor:UIColor.labelColor with:self.customView];\n    [_customLayer xy_setLayerBackgroundColor:UIColor.systemBackgroundColor with:self.customView];\n    ...\n}\n\n// Create color\n- (UIColor *)color {\n    if (!_color) {\n        _color = [UIColor xy_createWithLightColor:UIColor.blackColor darkColor:UIColor.whiteColor];\n    }\n    return _color;\n}\n```\n\n## License\n\n**XYColor** is under MIT license. See the [LICENSE](LICENSE) file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frayjiang16%2Fxycolor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frayjiang16%2Fxycolor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frayjiang16%2Fxycolor/lists"}