Code Monkey home page Code Monkey logo

ios-color-picker's Introduction

iOS Color Picker

Version License Platform

A reusable color picker component for iOS. Works for iPhone, iPad, in modal sheets, popovers... just about anywhere.

Using iOS-Color-Picker

Installation

The easiest way to use iOS-Color-Picker is with CocoaPods. Add the following line to your Podfile.

pod 'iOS-Color-Picker'

Otherwise, you need to include the following files in your project:

  • FCColorPickerViewController.h
  • FCColorPickerViewController.m
  • FCColorPickerViewController.xib
  • Resources/colormap.png

Using a Color Picker from a View Controller

Suppose you have a view controller with a color property you'd like to let the user pick. Make your view controller implement the FCColorPickerViewControllerDelegate protocol. Handle the color picked and the cancelled methods, and make a method that triggers showing the view controller.

-(IBAction)chooseColor:(id)sender {
    FCColorPickerViewController *colorPicker = [FCColorPickerViewController colorPicker];
    colorPicker.color = self.color;
    colorPicker.delegate = self;
    
    [colorPicker setModalPresentationStyle:UIModalPresentationFormSheet];
    [self presentViewController:colorPicker animated:YES completion:nil];
}

#pragma mark - FCColorPickerViewControllerDelegate Methods

-(void)colorPickerViewController:(FCColorPickerViewController *)colorPicker didSelectColor:(UIColor *)color {
    self.color = color;
    [self dismissViewControllerAnimated:YES completion:nil];
}

-(void)colorPickerViewControllerDidCancel:(FCColorPickerViewController *)colorPicker {
    [self dismissViewControllerAnimated:YES completion:nil];
}

The color picker has tintColor and backgroundColor properties for configuring its appearance.

Screenshots

iPhone

iPhone 5

iPhone 5

iPad

iPhone 5

iPhone 5

Example Project

An example project is included in /Example. Run pod install in the example directory to configure the project, then open the Xcode workspace.

ios-color-picker's People

Contributors

bitdeli-chef avatar fcanas avatar paulnicholson 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

ios-color-picker's Issues

Color Not Matching Swatch

Hi there, I tried to use your library in Swift. Color in the circle doesn't seem to be matching the swatch and the swatch seems to have been flipped. Have you encountered this issue? Thanks!!

image
image
image

Wrong gradient colors

The gradient bar along the bottom is showing the wrong colors. Problem is in this method of UIColor+Expanded.m:

  • (void)red:(CGFloat)r green:(CGFloat)g blue:(CGFloat)b toHue:(CGFloat *)pH saturation:(CGFloat *)pS brightness:(CGFloat *)pV {

in these lines:

    h *= 60.0f;                                 // Convert to degrees
    if (h < 0.0f) h += 360.0f;                  // Make non-negative

Need to change them to:

            h /= 6.0f;
            if (h < 0.0f) h += 1.0f;

(if you look at this history of UIColor+HSV.m you'll see this change was made there, but was never made to UIColor+Expanded.m). The issue is that hsv values are now stored between 0.0 and 1.0 in UIColor rather than 0 and 360. I don't want to change the file, as I'm sure there are probably more places that need changed and I don't really understand what all the code does.

Fix view controller initialization methods

The following line is allowed, but creates a view controller with no content.

FCColorPickerViewController()

It should either

  1. be annotated as unavailable
  2. be fixed so that it loads its view from the xib

Podfile

If you inherit search paths in your podfile it will be easier to use.

platform :ios, '9.0'
source 'https://github.com/CocoaPods/Specs.git'

target :ColorPicker do
    pod 'iOS-Color-Picker', path: '../'
end

target :SwiftyPicker do
    inherit! :search_paths
    use_frameworks!
    pod 'iOS-Color-Picker', path: '../'
end

Error using in project with deployment target iOS 9.3

At build time, this is the warning:

/Pods/iOS-Color-Picker/FCColorPickerViewController.xib: warning: Unsupported Configuration: This file is set to build for a version older than the deployment target. Functionality may be limited.

And at runtime it excepts out with

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </var/containers/Bundle/Application/94CE8315-3EF7-4415-879D-95D2B182EE46/test.app> (loaded)' with name 'FCColorPickerViewController''

Color (hue) does not match swatch position

Thank you for this easy-to-use color picker!

I have run into a bug - the color picker only displays a red hue, with varying saturation levels. The brightness works fine, so the only issue is the hue not following the swatch position. I have attached a screenshot, and I have made no modifications to the ios-color-picker code. This is on Xcode 9.4.1, compiling for iOS 11.

Please let me know what I can do to fix this.
Thomas

color picker screenshot

Initial brightness set to zero

When you click in the hue/saturation area to select a color, the initial brightness is set to zero (so the selected color is always black). I added this code to updateHueSatWithMovement in FCColorPickerViewController.m:

currentBrightness = 1.0;
CGPoint brightnessPosition;
brightnessPosition.x = (1.0-currentBrightness)*_gradientView.frame.size.width + _gradientView.frame.origin.x;
brightnessPosition.y = _gradientView.center.y;
_brightnessBar.center = brightnessPosition;

Not working in my Swift project

Can't figure it out, I copy the Swift example code pretty much verbatim but when I try to show the color picker in a button action I just get a grey background, no color picker. Any ideas?

Unable to manually set the location of the crosshairs/loop based on color

I use the method colorPickerWithColor:delegate to create the picker but the loop does not appear near the given color and is rendered off screen. Apparently the x-position is not calculated correctly due to an incorrect Hue value. (on line 133)

The formula expects a Hue value between 0.0 and 1.0 however the actual value used is the one that UIColor+Utilities returns, a value between 0 and 360.

This causes the actual resulting point to be something like (68955, 101.65)

Example:

Given the color

 [UIColor colorWithHue:0.69 saturation:0.65 brightness:0.65 alpha:1.0]

Then this is the result of the formula (248.40 is the hue value)

xpos = (248.40 * 278.00) + 11.00 = 69066.20

While I expect: (Got 0.69 using [_color getHue:&currentHue saturation:nil brightness:nil alpha:nil])

xpos = (0.69 * 278.00) + 11.00 = 202.82

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.