The elegant color picker missed in UIKit and SwiftUI.
This example GIF is from ElegantTimeline. For a simpler demonstration, you can look at either of the 3 demo projects in this repository.
ElegantColorPalette
is inspired by TimePage and is part of a larger repository of elegant demonstrations like this: TimePage Clone.
The top level view is an SKView
that presents an SKScene
of colors nodes. The color nodes are SKShapeNode
subclasses. When using this library, you are only interacting with the SKView
: all you have to do is configure the size of the view either through autolayout or size constraints and the view does the rest.
For SwiftUI:
import ElegantColorPalette
struct ExampleSwiftUIView: View {
@State private var selectedColor: PaletteColor = .kiwiGreen
var body: some View {
ColorPaletteBindingView(selectedColor: $selectedColor, colors: PaletteColor.allColors)
}
}
For UIKit(programmatically):
import ElegantColorPalette
struct ExampleUIKitViewController: UIViewController {
...
private lazy var paletteView: ColorPaletteView = {
let paletteView = ColorPaletteView(colors: PaletteColor.allColors)
paletteView.translatesAutoresizingMaskIntoConstraints = false
return paletteView
}()
override func viewDidLoad() {
super.viewDidLoad()
...
view.addSubview(paletteView)
NSLayoutConstraint.activate([
...
])
paletteView
.didSelectColor { [unowned self] color in
...
}
}
}
For UIKit(storyboard and XIB):
import ElegantColorPalette
struct ExampleUIKitViewController: UIViewController {
...
@IBOutlet weak var paletteView: ColorPaletteView!
override func viewDidLoad() {
super.viewDidLoad()
...
paletteView
.update(withColors: PaletteColor.allColors)
.didSelectColor { [unowned self] color in
...
}
}
}
Documentation coming soon...
There are 3 different demos, covering UIKit storyboards, XIBs and programmatic instantiation, and SwiftUI.
ElegantColorPalette
is available using the Swift Package Manager:
Using Xcode 11, go to File -> Swift Packages -> Add Package Dependency
and enter https://github.com/ThasianX/ElegantColorPalette
If you are using Package.swift
, you can also add ElegantColorPalette
as a dependency easily.
let package = Package(
name: "TestProject",
dependencies: [
.package(url: "https://github.com/ThasianX/ElegantColorPalette", from: "1.0.0")
],
targets: [
.target(name: "TestProject", dependencies: ["ElegantColorPalette"])
]
)
- iOS 13.0+
- Xcode 11.0+
If you find a bug, or would like to suggest a new feature or enhancement, it'd be nice if you could search the issue tracker first; while we don't mind duplicates, keeping issues unique helps us save time and considates effort. If you can't find your issue, feel free to file a new one.
This project is licensed under the MIT License - see the LICENSE file for details