Coder Social home page Coder Social logo

bolestudio2020 / efcolorpicker Goto Github PK

View Code? Open in Web Editor NEW

This project forked from efprefix/efcolorpicker

0.0 0.0 0.0 3.8 MB

A lightweight color picker in Swift.

Home Page: https://swiftpackageindex.com/EFPrefix/EFColorPicker

License: MIT License

Shell 0.28% Ruby 1.27% Swift 98.45%

efcolorpicker's Introduction

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

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

Version Needs
<5.0 Xcode 10.0+
Swift 4.2+
iOS 8.0+
5.x Xcode 10.2+
Swift 5.0+
iOS 8.0+

Installation

CocoaPods

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

pod 'EFColorPicker'

Carthage

You can use Carthage to install EFColorPicker by adding that to your Cartfile:

github "EFPrefix/EFColorPicker"

Swift Package Manager

The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the Swift compiler.

Once you have your Swift package set up, adding EFColorPicker as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies: [
    .package(url: "https://github.com/EFPrefix/EFColorPicker.git", .upToNextMinor(from: "5.2.2"))
]

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
colorSelectionController.setMode(mode: EFColorSelectionMode.all)

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

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

Apps using EFColorPicker

Author

EyreFree, [email protected]

License

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

efcolorpicker's People

Contributors

eyrefree avatar illaz avatar iklemix avatar hanks-hu avatar ningkexin avatar nissaba avatar andrewmika avatar culumn avatar dimakomar avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.