Giter Club home page Giter Club logo

efcolorpicker's Introduction

DEPRECATED, use UIColorPickerViewController / ColorPicker instead.


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

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

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

efcolorpicker's Issues

卡顿

改变亮度执行的drawWheelImage 会使界面卡顿.
我的解决方式是用rx来控制获取进度值的响应间隔.

Support Hex

Check List

Thanks for considering to open an issue. Before you submit your issue, please confirm these boxes are checked.

  • I have read the README.md, but there is no information I need.
  • I have searched in existing issues, but did find a same one.

Issue Description

Description

It would be great if users could see/input a hex string to select a color. It could be off by default like isColorTextFieldHidden

Reproduce

n/a

Other Comment

n/a

EFColorSelectionViewControllerDelegate not obj-c compatible.

to make the EFColorSelectionViewControllerDelegate compatible with OBJC it needs to be set this way.

@objc public protocol EFColorSelectionViewControllerDelegate: NSObjectProtocol {

    // Tells the data source to return the color components.
    // @param colorViewCntroller The color view.
    // @param color The new color value.
    func colorViewController(colorViewCntroller: EFColorSelectionViewController, didChangeColor color: UIColor)
}

New iOS 13 popover style doesn't play well with the Color Wheel

Issue Description
If presenting the Controller as a popover (as in the example provided in the README) the new presentation style introduced for iPhones in iOS 13.0 doesn't allow to drag inside the color wheel without the dismiss gesture of the popover being activated

This is easily fixed with the extension provided, but it would be a cool thing if the controller already expected the possibility this behavior

extension EFColorWheelView{
    override public func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
        if gestureRecognizer is UIPanGestureRecognizer{
            if let hsbView = self.superview as? EFHSBView{
                return !hsbView.isTouched
            }
        }
        return true
    }
}

I don't know what the proper "fix" might be, but there are some suggestions here
https://stackoverflow.com/questions/56718552/disable-gesture-to-pull-down-form-page-sheet-modal-presentation

ColorPicker Not Showing on iPad Pro Simulator

I followed your code and was able to display Colorpicker on iPhone devices(real and simulator) but I tried doing the same code on an iPad and it neither crashed or display the Colorpicker.

Please how do i go about this issue?
Thank you

Color wheel does not show brightness on open

It's related to issue #5. When opening a color that's already been set, the color wheel view doesn't include the brightness. Very noticeable when you set the color to black, tap done, then reopen.
color wheel brightness on open defect

Xcode 12.5 Beta, crash when moving point in color wheel

Issue Description

Crash "Simultaneous accesses to 0x7ffe78fac488, but modification requires exclusive access" when moving around the color Wheel

Description

When moving the the color wheel the app crashes in the getter of the hue property of EFColorWheelView, last access occurs at ef_selectedPoint(). Feel that something with the pointer use at onTouchEventWithPosition isn't working with the new Xcode version

Reproduce

Open the Color Picker Controller, move to the HSB section, move the point in the color wheel, happens immediatly.
Reproduced in the simulator, still haven't installed the Beta in a physical device, will try probably next week and return back

有两个建议

你好,首先这个库写的挺好,也挺实用,但是使用中有两个问题,用起来很不舒服。

swift写的很冗余,好多地方的可以写的更简洁。

1 、 比如 EFColorSelectionViewController.swift中,完全可以使用属性,就少写很多as? EFColorSelectionView

  func colorSelectionView() -> EFColorSelectionView {
       return self.view as? EFColorSelectionView ?? EFColorSelectionView()
   }

2、 很多冗余的类型。

  • let segmentControl: UISegmentedControl = UISegmentedControl(items: ["RGB", "HSB"] ) => let segmentControl = UISegmentedControl(items: ["RGB", "HSB"] )
  • segmentControl.addTarget(...,for: UIControl.Event.valueChanged) => segmentControl.addTarget(...,for: .valueChanged)

很多需要的属性方法,都没有public。比如 EFColorWheelView中的hue saturation brightness就不是public。

colorSelectionView.setSelectedIndex(index: .RGB, animated: false)

Check List

Thanks for considering to open an issue. Before you submit your issue, please confirm these boxes are checked.

  • I have read the README.md, but there is no information I need.
  • I have searched in existing issues, but did find a same one.

Issue Description

colorSelectionView.frame = CGRect(x: 0, y: 0, width: KScreenW, height: 400)
colorSelectionView.setSelectedIndex(index: .RGB, animated: false)

Description

'setSelectedIndex' is inaccessible due to 'internal' protection level

[Tell us about the issue]

Reproduce

[The steps to reproduce this issue. What are the parameters, where did you put your code, etc.]

Other Comment

[Add anything else here]

Crash in EFColorUtils.swift line 213

Hello we noticed a crash in file EFColorUtils.swift at line 231 "UInt64(blue * EFRGBColorComponentMaxValue),"

I noticed while on an exception breakpoint that for some reason the blue value comes out negative.
Tis so fare only happens with the blue color component. The crash I was able to break on the blue value vas at -0.00574635...

Will try to find out more.

crash log
Crashed: com.apple.main-thread
0 MLS-Touch 0x1052d9c84 specialized EFHexStringFromColor(color : UIColor) -> String? (EFColorUtils.swift:213)
1 MLS-Touch 0x1053756a8 EFHSBView.reloadData() -> () (EFHSBView.swift:72)
2 MLS-Touch 0x105376f04 EFHSBViewMLS_TouchEFColorView (EFHSBView.swift:56)
3 MLS-Touch 0x1051384c4 specialized EFColorSelectionView.color (EFColorSelectionView.swift:51)
4 MLS-Touch 0x1051381a0 EFColorSelectionView.colorView(colorView : EFColorView, didChangeColor : UIColor) -> () (EFColorSelectionView.swift)
5 MLS-Touch 0x105377d64 specialized EFHSBView.ef_colorDidChangeValue(sender : EFColorWheelView) -> () (EFHSBView.swift:231)
6 MLS-Touch 0x105376cf8 @objc EFHSBView.ef_colorDidChangeValue(sender : EFColorWheelView) -> () + 4313509112
7 UIKit 0x18e60164c -[UIApplication sendAction:to:from:forEvent:] + 96
8 UIKit 0x18e722870 -[UIControl sendAction:to:forEvent:] + 80
9 UIKit 0x18e607700 -[UIControl _sendActionsForEvents:withEvent:] + 440
10 MLS-Touch 0x10538a4fc specialized EFColorWheelView.onTouchEventWithPosition(point : CGPoint) -> () (EFColorWheelView.swift:126)
11 MLS-Touch 0x105389ad0 @objc EFColorWheelView.touchesEnded(Set, with : UIEvent?) -> () (EFColorWheelView.swift)
12 UIKit 0x18e68485c -[UIWindow _sendTouchesForEvent:] + 2040
13 UIKit 0x18e679890 -[UIWindow sendEvent:] + 3160
14 UIKit 0x18e6781d0 -[UIApplication sendEvent:] + 340
15 UIKit 0x1a48d762c -[UIApplicationAccessibility sendEvent:] + 100
16 UIKit 0x18ee59d1c __dispatchPreprocessedEventFromEventQueue + 2340
17 UIKit 0x18ee5c2c8 __handleEventQueueInternal + 4744
18 UIKit 0x18ee55368 __handleHIDEventFetcherDrain + 152
19 CoreFoundation 0x18483b404 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 24
20 CoreFoundation 0x18483ac2c __CFRunLoopDoSources0 + 276
21 CoreFoundation 0x18483879c __CFRunLoopRun + 1204
22 CoreFoundation 0x184758da8 CFRunLoopRunSpecific + 552
23 GraphicsServices 0x18673e020 GSEventRunModal + 100
24 UIKit 0x18e778758 UIApplicationMain + 236
25 MLS-Touch 0x104f48b1c main (main.m:33)
26 libdyld.dylib 0x1841e9fc0 start + 4

How to get the Hex Color Value or the Rgb Value

Can we be able to log og print the equivalent hex color value or the rgb value of the color ? for example how we will get the color value of self.view.backgroundColor = color -> this color can we get the hex or the rgb equivalent?

'setSelectedIndex' is inaccessible due to 'internal' protection level

Check List

Thanks for considering to open an issue. Before you submit your issue, please confirm these boxes are checked.

  • I have read the README.md, but there is no information I need.
  • I have searched in existing issues, but did find a same one.

Issue Description

colorSelectionView.setSelectedIndex(index: .RGB, animated: false)

Description

error: 'setSelectedIndex' is inaccessible due to 'internal' protection level

[Tell us about the issue]

Reproduce

[The steps to reproduce this issue. What are the parameters, where did you put your code, etc.]

Other Comment

[Add anything else here]

Problems with delegate

func colorViewController(_ colorViewCntroller: EFColorSelectionViewController, didChangeColor color: UIColor) does not work.

Because here:
self.delegate?.colorViewController(self, didChangeColor: color)

self.delegate always nil, despite that I set it

I fixed this by deleting weak here:

public WEAK var delegate: EFColorSelectionViewControllerDelegate?

Maybe I did something wrong?

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.