Latest 1.2.1
Homepage https://github.com/EFPrefix/EFColorPicker
License MIT
Platforms ios 8.0, requires ARC
Authors

EFColorPicker


EFColorPicker


EFColorPicker


EFColorPicker


EFColorPicker


EFColorPicker


EFColorPicker


EFColorPicker


EFColorPicker

EFColorPicker

EFColorPicker is a lightweight color picker in Swift, inspired by MSColorPicker.

中文介绍

Overview

Color picker component for iOS. It allows the user to select a color with color components. Key features:

  • iPhone & iPad support
  • Adaptive User Interface
  • Supports RGB and HSB color models
  • Well-documented
  • Compatible with iOS 8.0 (iPhone & iPad) and higher

Preview

iPhone iPad
EFColorPicker EFColorPicker EFColorPicker

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Then build and run EFColorPicker.xcworkspace in Xcode, the demo shows how to use and integrate the EFColorPicker into your project.

Requirements

  • iOS 8.0+
  • Xcode 10.1+
  • Swift 4.2+
  • CocoaPods 1.6.0.beta.2+

Installation

EFColorPicker is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'EFColorPicker'

Use

  1. First, include EFColorPicker in your project:
import EFColorPicker
  1. Next, we can call EFColorPicker with pure code:
let colorSelectionController = EFColorSelectionViewController()
let navCtrl = UINavigationController(rootViewController: colorSelectionController)
navCtrl.navigationBar.backgroundColor = UIColor.white
navCtrl.navigationBar.isTranslucent = false
navCtrl.modalPresentationStyle = UIModalPresentationStyle.popover
navCtrl.popoverPresentationController?.delegate = self
navCtrl.popoverPresentationController?.sourceView = sender
navCtrl.popoverPresentationController?.sourceRect = sender.bounds
navCtrl.preferredContentSize = colorSelectionController.view.systemLayoutSizeFitting(
    UILayoutFittingCompressedSize
)

colorSelectionController.delegate = self
colorSelectionController.color = self.view.backgroundColor ?? UIColor.white

if UIUserInterfaceSizeClass.compact == self.traitCollection.horizontalSizeClass {
    let doneBtn: UIBarButtonItem = UIBarButtonItem(
        title: NSLocalizedString("Done", comment: ""),
        style: UIBarButtonItemStyle.done,
        target: self,
        action: #selector(ef_dismissViewController(sender:))
    )
    colorSelectionController.navigationItem.rightBarButtonItem = doneBtn
}
self.present(navCtrl, animated: true, completion: nil)

Also we can use EFColorPicker in Storyboard:

if "showPopover" == segue.identifier {
    guard let destNav: UINavigationController = segue.destination as? UINavigationController else {
        return
    }
    if let size = destNav.visibleViewController?.view.systemLayoutSizeFitting(UILayoutFittingCompressedSize) {
        destNav.preferredContentSize = size
    }
    destNav.popoverPresentationController?.delegate = self
    if let colorSelectionController = destNav.visibleViewController as? EFColorSelectionViewController {
        colorSelectionController.delegate = self
        colorSelectionController.color = self.view.backgroundColor ?? UIColor.white

        if UIUserInterfaceSizeClass.compact == self.traitCollection.horizontalSizeClass {
            let doneBtn: UIBarButtonItem = UIBarButtonItem(
                title: NSLocalizedString("Done", comment: ""),
                style: UIBarButtonItemStyle.done,
                target: self,
                action: #selector(ef_dismissViewController(sender:))
            )
            colorSelectionController.navigationItem.rightBarButtonItem = doneBtn
        }
    }
}

You can control the visibility of color textField by change the isColorTextFieldHidden property of EFColorSelectionViewController, for example:

isColorTextFieldHidden: true isColorTextFieldHidden: false
EFColorPicker EFColorPicker EFColorPicker EFColorPicker

For more detail, please see the demo.

  1. Last but not the least, you should implement EFColorSelectionViewControllerDelegate so you can sense the color changes:
// MARK:- EFColorSelectionViewControllerDelegate
func colorViewController(colorViewCntroller: EFColorSelectionViewController, didChangeColor color: UIColor) {
    self.view.backgroundColor = color

    // TODO: You can do something here when color changed.
    print("New color: " + color.debugDescription)
}

PS

The first version of EFColorPicker is converted from MSColorPicker, thanks for sgl0v‘s work!

Author

EyreFree, [email protected]

License

EFColorPicker

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

Latest podspec

{
    "name": "EFColorPicker",
    "version": "1.2.1",
    "summary": "A lightweight color picker in Swift.",
    "description": "EFColorPicker is a lightweight color picker in Swift, inspired by MSColorPicker.",
    "homepage": "https://github.com/EFPrefix/EFColorPicker",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "EyreFree": "[email protected]"
    },
    "source": {
        "git": "https://github.com/EFPrefix/EFColorPicker.git",
        "tag": "1.2.1"
    },
    "social_media_url": "https://twitter.com/EyreFree777",
    "platforms": {
        "ios": "8.0"
    },
    "requires_arc": true,
    "source_files": "EFColorPicker/Classes/**/*"
}

Pin It on Pinterest

Share This