Welcome to the HexColors documentation!
Overview
The HexColors library is a powerful tool that provides developers with a vast collection of color utility functions for iOS applications. With HexColors, you can easily convert between different color formats, manipulate and generate color schemes, as well as access a wide range of pre-defined color palettes.
Installation
- Open your terminal.
- Navigate to your project directory.
- Run the following command to install HexColors using CocoaPods:
pod 'HexColors'
Usage
Converting Hex String to UIColor
HexColors provides a straightforward way to convert a hexadecimal color string into a UIColor object. This is particularly useful when setting the color of UI elements programmatically.
import HexColors
let whiteColor = UIColor(hex: "#FFFFFF")
Converting UIColor to Hex String
HexColors also enables you to convert a UIColor object back into its corresponding hexadecimal color string representation. This is helpful when storing or sharing color values.
import HexColors
let whiteColor = UIColor.white
let hexString = whiteColor.hexString
Manipulating Colors
HexColors provides various methods to manipulate colors.
- Lighten/Darken: Adjust the brightness of a color.
- Saturate/Desaturate: Modify the color’s saturation level.
- Grayscale: Convert a color to its grayscale equivalent.
- Blend: Blend two colors together.
import HexColors
let blueColor = UIColor(hex: "#0000FF")
let lighterBlue = blueColor.lighter(by: 20.0) // lighten by 20%
let darkerBlue = blueColor.darker(by: 30.0) // darken by 30%
Color Schemes
HexColors provides color scheme generation methods to help you create harmonious palettes based on a given color.
- Analogous Colors: Retrieve a set of colors that are adjacent to the given color on the color wheel.
- Complementary Color: Get the complementary color for a given color.
- Split Complementary Colors: Get two colors that are adjacent to the complementary color.
- Triad Colors: Generate three colors that are evenly spaced around the color wheel.
import HexColors
let redColor = UIColor(hex: "#FF0000")
let analogousColors = redColor.analogousColors // array of analogous colors
let complementaryColor = redColor.complementaryColor
Pre-defined Color Palettes
HexColors offers a selection of pre-defined color palettes, allowing you to easily access a variety of colors without manually specifying their hex values.
- Material Design Colors: A set of colors defined in Google’s Material Design guidelines.
- Flat UI Colors: A collection of colors commonly used in flat UI designs.
- System Colors: Colors from the iOS system’s color palette, including shades for light and dark mode.
import HexColors
let redColor = UIColor.flatRed()
let materialDesignColors = UIColor.materialDesign
Conclusion
The HexColors library provides developers with a range of powerful color manipulation, conversion, and generation features to enhance their iOS applications. By leveraging the utility functions and pre-defined color palettes, you can easily create visually appealing and consistent user interfaces.
For further information, please refer to the official HexColors documentation.