Skip to content

ThasianX/ElegantColorPalette

Folders and files

NameName
Last commit message
Last commit date
Jul 18, 2020
Aug 3, 2020
Aug 3, 2020
Aug 1, 2020
Aug 1, 2020
Aug 1, 2020
Jul 31, 2020
Aug 3, 2020
Jul 18, 2020
Aug 1, 2020
Aug 3, 2020

Repository files navigation

ElegantColorPalette

Platforms License: MIT

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.

Introduction

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.

Basic usage

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
                ...
            }
    }

}

Customization

Documentation coming soon...

Demos

There are 3 different demos, covering UIKit storyboards, XIBs and programmatic instantiation, and SwiftUI.

Installation

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"])
  ]
)

Requirements

  • iOS 13.0+
  • Xcode 11.0+

Contributing

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.

License

This project is licensed under the MIT License - see the LICENSE file for details