ColorWell

@objc(HBColorWell)
open class ColorWell : UIControl

ColorWell can be used to present the user’s color selection in your user interface. It optionally also supports drag-and-drop operations.

By default, drop interactions are supported, which causes a UIControl.Event.valueChanged event to be emitted. Optionally, drag operations can be enabled, allowing the color to be dropped elsewhere.

You can also use UIControl.Event.touchUpInside to perform an action, such as to initialise and present an instance of ColorPickerViewController.

  • Set the color to be displayed by the view.

    Declaration

    Swift

    @objc
    open var color: UIColor? { get set }
  • Override the default border color if desired.

    Declaration

    Swift

    @objc
    open var borderColor: UIColor? { get set }
  • Whether the user can begin a drag interaction from this view, allowing them to drop the color into a supporting app. The default is false.

    Declaration

    Swift

    @objc
    open var isDragInteractionEnabled: Bool { get set }
  • Whether the user can end a drag interaction by dropping on this view, allowing them to drag a color from a supporting app onto this view. The default is true.

    To handle a color being dropped on this view, add an action for the .valueChanged event. For example:

    colorWell.addTarget(self, action: #selector(self.handleColorDidChange(_:)), for: .valueChanged)
    

    Declaration

    Swift

    @objc
    open var isDropInteractionEnabled: Bool { get set }
  • Whether the user can long press (iPhone) or right-click (Mac/iPad) the view, allowing them to copy the color in various formats, or paste a color from another source.

    To handle a color being pasted via the context menu, add an action for the .valueChanged event. For example:

    colorWell.addTarget(self, action: #selector(self.handleColorDidChange(_:)), for: .valueChanged)
    

    Requires iOS 14 or newer.

    Declaration

    Swift

    @available(iOS 14, *)
    open override var isContextMenuInteractionEnabled: Bool { get set }