{"id":899,"url":"https://github.com/yannickl/DynamicColor","last_synced_at":"2025-08-06T13:31:59.976Z","repository":{"id":33051748,"uuid":"36687975","full_name":"yannickl/DynamicColor","owner":"yannickl","description":"Yet another extension to manipulate colors easily in Swift and SwiftUI","archived":false,"fork":false,"pushed_at":"2023-11-30T13:02:01.000Z","size":483,"stargazers_count":3046,"open_issues_count":18,"forks_count":144,"subscribers_count":55,"default_branch":"master","last_synced_at":"2024-10-29T11:27:22.649Z","etag":null,"topics":["color","gradient","hex","hex-strings","nscolor","swiftui","uicolor"],"latest_commit_sha":null,"homepage":"http://cocoadocs.org/docsets/DynamicColor","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/yannickl.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2015-06-01T20:47:55.000Z","updated_at":"2024-10-27T11:52:29.000Z","dependencies_parsed_at":"2024-01-29T16:57:55.466Z","dependency_job_id":"bfd4a6b6-7750-4d84-920b-754397aabde2","html_url":"https://github.com/yannickl/DynamicColor","commit_stats":{"total_commits":246,"total_committers":16,"mean_commits":15.375,"dds":0.2032520325203252,"last_synced_commit":"cf7c6eed080ea4b678592ae5af987c207ca8a232"},"previous_names":[],"tags_count":32,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yannickl%2FDynamicColor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yannickl%2FDynamicColor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yannickl%2FDynamicColor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yannickl%2FDynamicColor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yannickl","download_url":"https://codeload.github.com/yannickl/DynamicColor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228905441,"owners_count":17989766,"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","gradient","hex","hex-strings","nscolor","swiftui","uicolor"],"created_at":"2024-01-05T20:15:34.216Z","updated_at":"2024-12-09T14:30:43.068Z","avatar_url":"https://github.com/yannickl.png","language":"Swift","readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"http://yannickloriot.com/resources/dynamiccolor-header.png\" alt=\"DynamicColor\"\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"http://cocoadocs.org/docsets/DynamicColor/\"\u003e\u003cimg alt=\"Supported Platforms\" src=\"https://cocoapod-badges.herokuapp.com/p/DynamicColor/badge.svg\"/\u003e\u003c/a\u003e\n  \u003ca href=\"http://cocoadocs.org/docsets/DynamicColor/\"\u003e\u003cimg alt=\"Version\" src=\"https://cocoapod-badges.herokuapp.com/v/DynamicColor/badge.svg\"/\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/Carthage/Carthage\"\u003e\u003cimg alt=\"Carthage compatible\" src=\"https://img.shields.io/badge/Carthage-%E2%9C%93-brightgreen.svg?style=flat\"/\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/apple/swift-package-manager\"\u003e\u003cimg alt=\"Swift Package Manager compatible\" src=\"https://img.shields.io/badge/SPM-%E2%9C%93-brightgreen.svg?style=flat\"/\u003e\u003c/a\u003e\n  \u003ca href=\"https://travis-ci.org/yannickl/DynamicColor\"\u003e\u003cimg alt=\"Build status\" src=\"https://travis-ci.org/yannickl/DynamicColor.svg?branch=master\"/\u003e\u003c/a\u003e\n  \u003ca href=\"https://codecov.io/gh/yannickl/DynamicColor\"\u003e\u003cimg src=\"https://codecov.io/gh/yannickl/DynamicColor/branch/master/graph/badge.svg\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n**DynamicColor** provides powerful methods to manipulate colors in an easy way in Swift and SwiftUI.\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"http://yannickloriot.com/resources/dynamiccolor-sample-screenshot.png\" alt=\"example screenshot\" width=\"300\" /\u003e\n  \u003cimg src=\"http://yannickloriot.com/resources/dynamicgradient-sample-screenshot.png\" alt=\"example screenshot\" width=\"300\" /\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"#requirements\"\u003eRequirements\u003c/a\u003e • \u003ca href=\"#usage\"\u003eUsage\u003c/a\u003e • \u003ca href=\"#installation\"\u003eInstallation\u003c/a\u003e • \u003ca href=\"#contribution\"\u003eContribution\u003c/a\u003e • \u003ca href=\"#contact\"\u003eContact\u003c/a\u003e • \u003ca href=\"#license-mit\"\u003eLicense\u003c/a\u003e\n\u003c/p\u003e\n\n## Requirements\n\n- iOS 11.0+ / Mac OS X 10.11+ / tvOS 11.0+ / watchOS 4.0+\n- Xcode 10.2+\n- Swift 5.0+\n\n## Usage\n\n#### Creation (Hex String)\n\nFirstly, DynamicColor provides useful initializers to create colors using hex strings or values:\n\n```swift\nlet color = UIColor(hexString: \"#3498db\")\n// equivalent to\n// color = UIColor(hex: 0x3498db)\n```\n\nTo be platform independent, the typealias `DynamicColor` can also be used:\n\n```swift\nlet color = DynamicColor(hex: 0x3498db)\n// On iOS, WatchOS or tvOS, equivalent to\n// color = UIColor(hex: 0x3498db)\n// On OSX, equivalent to\n// color = NSColor(hex: 0x3498db)\n```\n\nYou can also retrieve the RGBA value and components very easily using multiple methods like `toHexString`, `toHex`, `toRGBA`, etc.\n\n##### SwiftUI\n\nFrom the v5, DynamicColor also support basic methods to create and manipulate colors with SwiftUI.\n\n```swift\nlet color = Color(hex: 0x3498db)\n```\n\n#### Darken \u0026 Lighten\n\nThese two create a new color by adjusting the lightness of the receiver. You have to use a value between 0 and 1.\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"http://yannickloriot.com/resources/dynamiccolor-darkenlighten.png\" alt=\"lighten and darken color\" width=\"280\"/\u003e\n\u003c/p\u003e\n\n```swift\nlet originalColor = DynamicColor(hexString: \"#c0392b\")\n\nlet lighterColor = originalColor.lighter()\n// equivalent to\n// lighterColor = originalColor.lighter(amount: 0.2)\n\nlet darkerColor = originalColor.darkened()\n// equivalent to\n// darkerColor = originalColor.darkened(amount: 0.2)\n```\n\n#### Saturate, Desaturate \u0026 Grayscale\n\nThese will adjust the saturation of the color object, much like `darkened` and `lighter` adjusted the lightness. Again, you need to use a value between 0 and 1.\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"http://yannickloriot.com/resources/dynamiccolor-saturateddesaturatedgrayscale.png\" alt=\"saturate, desaturate and grayscale color\" width=\"373\"/\u003e\n\u003c/p\u003e\n\n```swift\nlet originalColor = DynamicColor(hexString: \"#c0392b\")\n\nlet saturatedColor = originalColor.saturated()\n// equivalent to\n// saturatedColor = originalColor.saturated(amount: 0.2)\n\nlet desaturatedColor = originalColor.desaturated()\n// equivalent to\n// desaturatedColor = originalColor.desaturated(amount: 0.2)\n\n// equivalent to\n// let grayscaledColor = originalColor.grayscaled(mode: .luminance)\nlet grayscaledColor = originalColor.grayscaled()\n\nlet grayscaledColorLuminance = originalColor.grayscaled(mode: .luminance)\nlet grayscaledColorLightness = originalColor.grayscaled(mode: .lightness)\nlet grayscaledColorAverage = originalColor.grayscaled(mode: .average)\nlet grayscaledColorValue = originalColor.grayscaled(mode: .value)\n```\n\n#### Adjust-hue \u0026 Complement\n\nThese adjust the hue value of the color in the same way like the others do. Again, it takes a value between 0 and 1 to update the value.\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"http://yannickloriot.com/resources/dynamiccolor-adjustedhuecomplement.png\" alt=\"ajusted-hue and complement color\" width=\"280\"/\u003e\n\u003c/p\u003e\n\n```swift\nlet originalColor = DynamicColor(hex: 0xc0392b)\n\n// Hue values are in degrees\nlet adjustHueColor = originalColor.adjustedHue(amount: 45)\n\nlet complementedColor = originalColor.complemented()\n````\n\n#### Tint \u0026 Shade\n\nA tint is the mixture of a color with white and a shade is the mixture of a color with black. Again, it takes a value between 0 and 1 to update the value.\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"http://yannickloriot.com/resources/dynamiccolor-tintshadecolor.png\" alt=\"tint and shade color\" width=\"280\"/\u003e\n\u003c/p\u003e\n\n```swift\nlet originalColor = DynamicColor(hexString: \"#c0392b\")\n\nlet tintedColor = originalColor.tinted()\n// equivalent to\n// tintedColor = originalColor.tinted(amount: 0.2)\n\nlet shadedColor = originalColor.shaded()\n// equivalent to\n// shadedColor = originalColor.shaded(amount: 0.2)\n```\n\n#### Invert\n\nThis can invert the color object. The red, green, and blue values are inverted, while the opacity is left alone.\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"http://yannickloriot.com/resources/dynamiccolor-invert.png\" alt=\"invert color\" width=\"187\"/\u003e\n\u003c/p\u003e\n\n```swift\nlet originalColor = DynamicColor(hexString: \"#c0392b\")\n\nlet invertedColor = originalColor.inverted()\n```\n\n#### Mix\n\nThis can mix a given color with the receiver. It takes the average of each of the RGB components, optionally weighted by the given percentage (value between 0 and 1).\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"http://yannickloriot.com/resources/dynamiccolor-mixcolor.png\" alt=\"mix color\" width=\"373\"/\u003e\n\u003c/p\u003e\n\n```swift\nlet originalColor = DynamicColor(hexString: \"#c0392b\")\n\nlet mixedColor = originalColor.mixed(withColor: .blue)\n// equivalent to\n// mixedColor = originalColor.mixed(withColor: .blue, weight: 0.5)\n// or\n// mixedColor = originalColor.mixed(withColor: .blue, weight: 0.5, inColorSpace: .rgb)\n```\n\n#### Gradients\n\n**DynamicColor** provides an useful object to work with gradients: **DynamicGradient**. It'll allow you to pick color from gradients, or to build a palette using different color spaces (.e.g.: *RGB*, *HSL*, *HSB*, *Cie L\\*a\\*b\\**).\n\nLet's define our reference colors and the gradient object:\n```swift\nlet blue   = UIColor(hexString: \"#3498db\")\nlet red    = UIColor(hexString: \"#e74c3c\")\nlet yellow = UIColor(hexString: \"#f1c40f\")\n\nlet gradient = DynamicGradient(colors: [blue, red, yellow])\n// equivalent to\n// let gradient = [blue, red, yellow].gradient\n```\n\n##### RGB\n\nLet's build the RGB palette (the default color space) with 8 colors:\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"http://yannickloriot.com/resources/dynamicgradient-rgb\" alt=\"RGB gradient\"/\u003e\n\u003c/p\u003e\n\n```swift\nlet rgbPalette = gradient.colorPalette(amount: 8)\n```\n\n##### HSL\n\nNow if you want to change the gradient color space to have a different effect, just write the following lines:\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"http://yannickloriot.com/resources/dynamicgradient-hsl\" alt=\"HSL gradient\"/\u003e\n\u003c/p\u003e\n\n```swift\nlet hslPalette = gradient.colorPalette(amount: 8, inColorSpace: .hsl)\n```\n\n##### Cie L\\*a\\*b\\*\n\nOr if you prefer to work directly with array of colors, you can:\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"http://yannickloriot.com/resources/dynamicgradient-lab\" alt=\"Cie L*a*b* gradient\"/\u003e\n\u003c/p\u003e\n\n```swift\nlet labPalette = [blue, red, yellow].gradient.colorPalette(amount: 8, inColorSpace: .lab)\n```\n\n#### And many more...\n\n`DynamicColor` also provides many another useful methods to manipulate the colors like hex strings, color components, color spaces, etc. To go further, take a look at the example project.\n\n## Installation\n\n#### CocoaPods\n\nInstall CocoaPods if not already available:\n\n``` bash\n$ [sudo] gem install cocoapods\n$ pod setup\n```\nGo to the directory of your Xcode project, and Create and Edit your *Podfile* and add _DynamicColor_:\n\n``` bash\n$ cd /path/to/MyProject\n$ touch Podfile\n$ edit Podfile\nsource 'https://github.com/CocoaPods/Specs.git'\nplatform :ios, '8.0'\n\nuse_frameworks!\npod 'DynamicColor', '~\u003e 5.0.0'\n```\n\nInstall into your project:\n\n``` bash\n$ pod install\n```\n\nOpen your project in Xcode from the .xcworkspace file (not the usual project file):\n\n``` bash\n$ open MyProject.xcworkspace\n```\n\nYou can now `import DynamicColor` framework into your files.\n\n#### Carthage\n\n[Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager that automates the process of adding frameworks to your Cocoa application.\n\nYou can install Carthage with [Homebrew](http://brew.sh/) using the following command:\n\n```bash\n$ brew update\n$ brew install carthage\n```\n\nTo integrate `DynamicColor` into your Xcode project using Carthage, specify it in your `Cartfile` file:\n\n```ogdl\ngithub \"yannickl/DynamicColor\" \u003e= 5.0.0\n```\n\n#### Swift Package Manager\nYou can use [The Swift Package Manager](https://swift.org/package-manager) to install `DynamicColor` by adding the proper description to your `Package.swift` file:\n```swift\nimport PackageDescription\n\nlet package = Package(\n    name: \"YOUR_PROJECT_NAME\",\n    targets: [],\n    dependencies: [\n        .package(url: \"https://github.com/yannickl/DynamicColor.git\", from: \"5.0.0\")\n    ]\n)\n```\n\nNote that the [Swift Package Manager](https://swift.org/package-manager) is still in early design and development, for more information checkout its [GitHub Page](https://github.com/apple/swift-package-manager).\n\n#### Manually\n\n[Download](https://github.com/YannickL/DynamicColor/archive/master.zip) the project and copy the `DynamicColor` folder into your project to use it in.\n\n## Contribution\n\nContributions are welcomed and encouraged *♡*.\n\n## Contact\n\nYannick Loriot\n - [https://21.co/yannickl/](https://21.co/yannickl/)\n - [https://twitter.com/yannickloriot](https://twitter.com/yannickloriot)\n\n## License (MIT)\n\nCopyright (c) 2015-present - Yannick Loriot\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\nall copies 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\nTHE SOFTWARE.\n","funding_links":[],"categories":["Color","Libs","Swift","UI","Colors [🔝](#readme)"],"sub_categories":["Linter","Colors","Content","Color","Other free courses"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyannickl%2FDynamicColor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyannickl%2FDynamicColor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyannickl%2FDynamicColor/lists"}