Introduction
Welcome to the documentation for DynamicColor!
DynamicColor is a powerful Swift library that provides an easy way to manipulate colors, generate color schemes, and perform various color-related operations
Installation
CocoaPods
- Open your Terminal and navigate to your Xcode project’s root directory.
- Run the command
pod init
. - Open your
Podfile
and add the following line: - Save the
Podfile
and runpod install
command in Terminal. - Close your Xcode project and open the newly generated
xcworkspace
file. - Now you can import DynamicColor in your project using
import DynamicColor
.
pod 'DynamicColor'
Swift Package Manager
- In Xcode, go to: File > Swift Packages > Add Package Dependency.
- Enter the repository URL
https://github.com/yannickl/DynamicColor.git
- Specify the version rules based on your preference.
- Click Next and wait for the Swift package manager to resolve the dependencies.
- Choose the DynamicColor package and add it to your target.
- Now you can import DynamicColor in your project using
import DynamicColor
.
Usage
Generating Colors
The DynamicColor
library provides several methods to generate different types of colors. Here are some examples:
Solid Colors
// Create a solid color with RGB values
let color1 = DynamicColor(red: 255, green: 0, blue: 0)
// Create a solid color with hexadecimal value
let color2 = DynamicColor(hexString: "#FF0000")
// Create a solid color with UIColor
let color3 = DynamicColor(cgColor: UIColor.blue.cgColor)
Gradient Colors
// Create a gradient color from a starting color to an ending color
let gradient = DynamicGradientColor(start: .red, end: .yellow)
let colorArray = gradient.colors
Color Schemes
// Generate an array of colors for a given base color
let baseColor = DynamicColor(red: 0, green: 128, blue: 255)
let scheme = baseColor.scheme(.complementary)
let colors = scheme.colors
Color Operations
DynamicColor provides various methods to manipulate colors. Here are some examples:
Lighten
// Lighten a color by a specific percentage
let color = DynamicColor(red: 128, green: 128, blue: 128)
let lighterColor = color.lighter(amount: 0.2)
Darken
// Darken a color by a specific percentage
let color = DynamicColor(red: 128, green: 128, blue: 128)
let darkerColor = color.darker(amount: 0.3)
Blend
// Blend two colors together
let color1 = DynamicColor(hexString: "#FF0000")
let color2 = DynamicColor(hexString: "#00FF00")
let blendedColor = color1.blend(with: color2, alpha: 0.5)
Documentation Reference
For detailed documentation and usage guidelines, please refer to the official DynamicColor GitHub repository.
Conclusion
Congratulations! You have successfully set up and started using DynamicColor in your Swift project. Have fun exploring the various color manipulation features it offers!