Make dynamic color initializers public.
Simple extensions for working with Color (SwiftUI) and UIColor (UIKit).
Color
UIColor
For installation with Swift Package Manager, simply add the following to your Package.swift:
Package.swift
.package(url: "https://github.com/lipka/Color", from: "0.1.0")
You can use the convenience initializers to initialize a color with a hex code. Supports 12-bit (FFF), 24-bit (FFFFFF) and 32-bit RGBA (FFFFFFFF) hex codes, that can optionally be prefixed with a pound sign.
FFF
FFFFFF
FFFFFFFF
Color(hex: "FF00FF") Color(hex: "#F0F", alpha: 0.5) UIColor(hex: "FF00FF") UIColor(hex: "#F0F", alpha: 0.5)
You can use the adjust method to easily adjust all or only specific components of a color.
adjust
UIColor.blue.adjust(red: 0.1, green: 0, blue: 0, alpha: 0) UIColor.blue.adjust(0.1)
This is especially useful for deriving colors for highlighted or selected states. For example when using Button:
import Button ... let button = Button() button.setBackgroundColor(.blue, for: .normal) button.setBackgroundColor(.blue.adjust(0.1), for: .highlighted)
Shorthand notation for creating dynamic colors (light/dark mode).
Color(light: Color.white, dark: Color.black) UIColor(light: UIColor.white, dark: UIColor.black)
©Copyright 2023 CCF 开源发展委员会 Powered by Trustie& IntelliDE 京ICP备13000930号
Color
Simple extensions for working with
Color
(SwiftUI) andUIColor
(UIKit).Installation
Swift Package Manager
For installation with Swift Package Manager, simply add the following to your
Package.swift
:Usage
Hex Colors
You can use the convenience initializers to initialize a color with a hex code. Supports 12-bit (
FFF
), 24-bit (FFFFFF
) and 32-bit RGBA (FFFFFFFF
) hex codes, that can optionally be prefixed with a pound sign.Adjusting Colors
You can use the
adjust
method to easily adjust all or only specific components of a color.This is especially useful for deriving colors for highlighted or selected states. For example when using Button:
Dynamic Colors
Shorthand notation for creating dynamic colors (light/dark mode).