Skip to content

a simple PopupDialog for picking a color from a list of colors

License

Notifications You must be signed in to change notification settings

Kautenja/UIPopupColorPicker

Repository files navigation

UIPopupColorPicker

swift-badge carthage-badge

Screenshots

The standard theme

An example of custom theme utilizing tint color, font, and a custom list of colors

Installation

Carthage

add the folowing to your Carfile:

github "kautenja/UIPopupColorPicker" ~> 1.1

Example

To run the example project, clone the repo, and it in Xcode on devices of your choosing, there is an example UI setup to access the picker.

Code Usage

Creation

UIPopupColorPicker is accessed through the single static function:

let _ = UIPopupColorPicker.show(on: self, block: nil)

This function returns an instance of BColorPicker in case you might want to manipulate some of the controller manually.

Customization

let popup = UIPopupColorPicker.show(on: self, block: nil)
popup.tintColor = #colorLiteral(red: 0.1568514521, 
                                green: 0.680490051, 
                                blue: 0.9768045545, 
                                alpha: 1)
popup.buttonFont = UIFont(name: "HelveticaNeue", size: 18.0)!
popup.colorList = [UIColor.gray, UIColor.blue, UIColor.yellow]

Callback

One way of handling color change is to implement a handler function

/// Handle a color selection from UIPopupColorPicker
func colorDidChange(to color: UIColor?) {
    
}

let _ = UIPopupColorPicker.show(on: self, block: colorDidChange)

or like this using an escaping closure

let _ = UIPopupColorPicker.show(on: self) { color in
    // handle color change with escaping closure
}

Code Samples

see ViewController for a working example of the popup.

License

TL;DR do what you want with it.

UIPopupColorPicker is available under the MIT license. See the LICENSE file for more info.