A reusable color picker component for iOS. Works for iPhone, iPad, in modal sheets, popovers... just about anywhere.
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
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.
An example project is included in /Example
. Run pod install
in the example directory to configure the project, then open the Xcode workspace.