{"id":22015886,"url":"https://github.com/pircate/thematic","last_synced_at":"2025-03-23T09:14:27.665Z","repository":{"id":56924183,"uuid":"397093747","full_name":"Pircate/Thematic","owner":"Pircate","description":null,"archived":false,"fork":false,"pushed_at":"2022-06-10T15:10:57.000Z","size":170,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-01T05:02:30.503Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/Pircate.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":"2021-08-17T04:16:06.000Z","updated_at":"2021-11-10T08:14:54.000Z","dependencies_parsed_at":"2022-08-21T05:20:50.268Z","dependency_job_id":null,"html_url":"https://github.com/Pircate/Thematic","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pircate%2FThematic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pircate%2FThematic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pircate%2FThematic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pircate%2FThematic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Pircate","download_url":"https://codeload.github.com/Pircate/Thematic/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245078198,"owners_count":20557282,"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-30T04:29:46.012Z","updated_at":"2025-03-23T09:14:27.626Z","avatar_url":"https://github.com/Pircate.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Thematic\n\n[![CI Status](https://img.shields.io/travis/gao497868860@163.com/Thematic.svg?style=flat)](https://travis-ci.org/gao497868860@163.com/Thematic)\n[![Version](https://img.shields.io/cocoapods/v/Thematic.svg?style=flat)](https://cocoapods.org/pods/Thematic)\n[![License](https://img.shields.io/cocoapods/l/Thematic.svg?style=flat)](https://cocoapods.org/pods/Thematic)\n[![Platform](https://img.shields.io/cocoapods/p/Thematic.svg?style=flat)](https://cocoapods.org/pods/Thematic)\n\n## Example\n\nTo run the example project, clone the repo, and run `pod install` from the Example directory first.\n\n## Requirements\n\n* iOS 9.0\n* Swift 5.2\n\n## Installation\n\nThematic is available through [CocoaPods](https://cocoapods.org). To install\nit, simply add the following line to your Podfile:\n\n```ruby\npod 'Thematic'\n```\n\n## Usage\n\n* ### 创建一个主题\n\n```swift\npublic class DarkTheme: Theme {\n    \n    public init() {}\n    \n    /// 资源的唯一标识符\n    public var identifier: String { UserInterfaceTheme.dark.description }\n    \n    /// 颜色资源的加载方式，分为 xcassets 和 映射表两种方式\n    public var colorAssetType: ColorAssetType {\n        .mapTable\n    }\n    \n    /// 图片资源的加载方式，分为 xcassets 和文件路径两种方式\n    public var imageAssetType: ImageAssetType {\n        .xcassets\n    }\n    \n    /// 如果是 xcassets 方式加载颜色，需要实现格式化名字的方法，一般用标识符做文件夹加以区分。\n    /// eg. dark/[colorName]，可以查看 Demo 里面的 Theme.xcassets\n    public func colorAssetName(_ assetName: String) -\u003e String {\n        \"\\(identifier)/\\(assetName)\"\n    }\n    \n    /// 如果是映射表方式加载颜色，需要提供一张颜色资源映射表\n    public func colorAssets(in bundle: Bundle) -\u003e Assets {\n        loadAssets(in: bundle)\n    }\n    \n    /// 如果是 xcassets 方式加载图片，需要实现格式化名字的方法，一般用标识符做文件夹加以区分。\n    /// eg. dark/[imageName]，，可以查看 Demo 里面的 Theme.xcassets\n    public func imageAssetName(_ assetName: String) -\u003e String {\n        \"\\(identifier)/\\(assetName)\"\n    }\n    \n    /// 如果是文件路径方式加载图片，如果生成文件所在的路径名称\n    public func imageAssetPath(_ assetName: String) -\u003e String {\n        \"\\(assetsDirectory)/\\(assetName)\"\n    }\n}\n```\n\n* ### 应用主题\n\n```swift\n/// 添加资源所在的 bundle，比如资源文件在主工程就添加 main bundle\nThemeManager.shared.appendResourceBundle(.main)\n\nif #available(iOS 13.0, *) {\n  /// iOS 13 之后可以设置跟随系统，会在 APP 激活的时候自动切换主题\n  ThemeManager.shared.applyAutomaticTheme(true)\n} else {\n  /// 应用 light 主题\n  ThemeManager.shared.applyUserInterfaceTheme(.light)\n}\n```\n\n* ### 设置颜色或图片\n\n```swift\n/// 设置主题颜色\nview.backgroundColor = UIColor(assetName: \"main\", in: .main)\n\n/// 设置主题图片\nimageView.image = UIImage(assetName: \"sleep\", in: .main)\n\n```\n\n## Author\n\ngao497868860@163.com, Pircate\n\n## License\n\nThematic is available under the MIT license. See the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpircate%2Fthematic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpircate%2Fthematic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpircate%2Fthematic/lists"}