StikColors is a lightweight Swift Package that provides:
- Hex-based Color Support: Easily convert between SwiftUI
Color
and hex strings. - Reusable Color Picker View: A simple SwiftUI
ColorPicker
component that binds to a hex string for seamless color customization.
- Initialize
Color
from a hex string. - Convert
Color
back to a hex string. - A SwiftUI ColorPicker view that works with hex strings using a simple binding.
To add StikColors to your Xcode project:
- In Xcode, go to File > Add Packages....
- Enter the repository URL:
https://github.com/0-Blu/StikColors
- Select the latest version and finish.
First, import the package into your Swift file:
import StikColors
You can create a SwiftUI Color
from a hex string and convert it back to hex:
import SwiftUI
import StikColors
// Create a Color from a hex string
let color = Color(hex: "#FF5733")
// Convert a Color back to a hex string
let hexValue = color?.toHex() // Output: "#FF5733"
The StikColorPickerView
binds a hex string to a SwiftUI ColorPicker
, allowing users to pick a color and automatically update the hex value.
import SwiftUI
import StikColors
struct ContentView: View {
@State private var backgroundColorHex: String = "#FF5733"
var body: some View {
VStack {
Text("Hello, StikColors!")
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color(hex: backgroundColorHex)) // Apply selected color
// ColorPicker View
StikColorPickerView(colorHex: $backgroundColorHex)
.padding()
}
}
}
When using the StikColorPickerView
, you will:
- See a color picker.
- Update the
backgroundColorHex
automatically when a new color is selected.
Initializes a Color
from a hex string:
- Input: Hex string (e.g.,
#FF5733
) - Output: SwiftUI
Color
Converts a Color
to a hex string:
- Output: Hex string (e.g.,
#FF5733
)
A SwiftUI view that provides a ColorPicker
and updates the bound hex string.
Parameters:
colorHex
: ABinding<String>
representing the hex string.
- iOS 15.0+
- Swift 5.5+
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Please open an issue or submit a pull request if you would like to enhance StikColors.
Developed by 0-Blu.