A customizable color picker for iOS in Swift

Overview

alt text

Language: Swift 5 License: MIT Platform: iOS

IGColorPicker is a fantastic color picker 🎨 written in Swift.

alt text

Table of Contents

Documentation

Colors

The color picker comes with our set of colors:

alt text

But if you don't like them, you are free to use your own colors πŸ– :

colorPickerView.colors = [UIColor.red, UIColor.yellow, UIColor.green, UIColor.black]

Style

  • style enum: look and feel of color picker cells

    • circle

      alt text

    • square

      alt text

  • selectionStyle enum: style applied when a color is selected

    • check

      alt text

    • none

      alt text

Other features

  • preselectedIndex Int?: the index of the preselected color in the color picker

  • isSelectedColorTappable Bool: if true, the selected color can be deselected by a tap

  • scrollToPreselectedIndex Bool: if true, the preselectedIndex is showed in the center of the color picker

Installation

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

pod 'IGColorPicker'

Example

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

Getting Started

ColorPickerView

ColorPickerView is just a class that inheritance from UIView, so you can both use a storyboard or you can create the color picker programmatically:

Storyboard

  • Add a UIView to the storyboard. Go to the Identity inspector and in set its class to ColorPickerView.
  • Just drag and drop the view in the correct class πŸ€™πŸ»

Programmatically

Just initialize the color picker like one would initialize a UIView, and add it as a subview to your view hierarchy.

import IGColorPicker

class ViewController {
  var colorPickerView: ColorPickerView!

  override func viewDidLoad() {
    super.viewDidLoad()

    colorPickerView = ColorPickerView(frame: CGRect(x: 0.0, y: 0.0, width: widthSize, height: heightSize))
    view.addSubview(colorPickerView)
  }

}

Delegate

ColorPickerViewDelegate is the delegate protocol that recognizes the tap gesture on a color. This is an option delegate, but if you need to know when the user selects a color you should implement it.

// Set the delegate πŸ™‹πŸ»β€β™‚οΈ
colorPickerView.delegate = self

// MARK: - ColorPickerViewDelegate
extension ViewController: ColorPickerViewDelegate {

  func colorPickerView(_ colorPickerView: ColorPickerView, didSelectItemAt indexPath: IndexPath) {
    // A color has been selected
  }

  // This is an optional method
  func colorPickerView(_ colorPickerView: ColorPickerView, didDeselectItemAt indexPath: IndexPath) {
    // A color has been deselected
  }

}

Layout

Every developer can customize the color picker layout in the way to fit with their design. To do that you have to implement our layout delegate ColorPickerViewDelegateFlowLayout

// Set the delegate πŸ™‹πŸ»β€β™‚οΈ
colorPickerView.layoutDelegate = self

// MARK: - ColorPickerViewDelegateFlowLayout
extension ViewController: ColorPickerViewDelegateFlowLayout {

  // ------------------------------------------------------------------
  // All these methods are optionals, your are not to implement them πŸ––πŸ»
  // ------------------------------------------------------------------

  func colorPickerView(_ colorPickerView: ColorPickerView, sizeForItemAt indexPath: IndexPath) -> CGSize {
    // The size for each cell
    // πŸ‘‰πŸ» WIDTH AND HEIGHT MUST BE EQUALS!
  }

  func colorPickerView(_ colorPickerView: ColorPickerView, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
    // Space between cells
  }

  func colorPickerView(_ colorPickerView: ColorPickerView, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
    // Space between rows
  }

  func colorPickerView(_ colorPickerView: ColorPickerView, insetForSectionAt section: Int) -> UIEdgeInsets {
    // Inset used aroud the view
  }

}

Project Details

Requirements

  • Swift 4.1
  • Xcode 9.0+
  • iOS 8.3+

Contributing

Feel free to collaborate with ideas πŸ’­ , issues ⁉️ and/or pull requests πŸ”ƒ .

Here is a list of ToDo about bug fix and new features you can work on:

  • Custom check size
  • Support to custom view in ColorPickerViewSelectStyle
  • Support custom style in ColorPickerViewStyle
  • Substitute M13Checkbox with another framework. Or just create a custom checkbox with animation

P.S. If you use IGColorPicker in your app we would love to hear about it! πŸ˜‰

License

Copyright (c) 2018 iGenius Srl

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Comments
  • Pod not found

    Pod not found

    I've added the line pod 'IGColorPicker' to my podfile, but I get [!] Unable to find a specification for IGColorPicker

    Similarly

    $ pod search "IGColorPicker"
    [!] Unable to find a pod with name, author, summary, or description matching `IGColorPicker`
    
    
    invalid 
    opened by sigmundfridge 5
  • Updates version of M13Checkbox is not supporting.

    Updates version of M13Checkbox is not supporting.

    • M13Checkbox (= 3.2.2) required by Podfile.lock
    • M13Checkbox (~> 2.2.0) required by IGColorPicker (0.2.0) This is the error I'm getting. Please help me in solving this.
    opened by sri1sri 2
  • Scroll to preselectedIndex doesn't work correctly

    Scroll to preselectedIndex doesn't work correctly

    I tried to scroll this Picker to a default value, and unfortunately, it works only from viewDidAppear.

        override func viewDidAppear(_ animated: Bool) {
                colorPicker.preselectedIndex = Int(task.colorIndex)
        }
    

    If I try to use from viewDidLoad or from viewWillAppear, it doesn't work at all. However viewDidAppear it is not very suitable for it, because it shows colors and scrolls only after. It looks like a bug.

    opened by AmirL 4
  • IGColorPicker subview doesn't respond to gestures

    IGColorPicker subview doesn't respond to gestures

    I'm just following the basic code in the documentation and put this in my viewDidLoad:

    // Setup colorPickerView
        colorPickerView = ColorPickerView(frame: CGRect(x: 0.0, y: 0.0, width: 200, height: 100))
        
        colorPickerView.delegate = self
        colorPickerView.layoutDelegate = self
        colorPickerView.style = .circle
        colorPickerView.selectionStyle = .check
        colorPickerView.isSelectedColorTappable = true
        colorPickerView.backgroundColor = .systemGray3
        
        
        colorPickerView.colors = [
        UIColor(red: 0.114, green: 0.169, blue: 0.325, alpha: 1.000),
        UIColor(red: 0.494, green: 0.141, blue: 0.325, alpha: 1.000),
        UIColor(red: 0.000, green: 0.529, blue: 0.318, alpha: 1.000),
        UIColor(red: 1.000, green: 0.000, blue: 0.302, alpha: 1.000),
        UIColor(red: 1.000, green: 0.639, blue: 0.000, alpha: 1.000),
        UIColor(red: 1.000, green: 0.925, blue: 0.153, alpha: 1.000),
        UIColor(red: 0.000, green: 0.898, blue: 0.212, alpha: 1.000),
        UIColor(red: 0.161, green: 0.682, blue: 1.000, alpha: 1.000),
        UIColor(red: 0.514, green: 0.463, blue: 0.612, alpha: 1.000),
        UIColor(red: 1.000, green: 0.467, blue: 0.659, alpha: 1.000)]
    
        jpTextView.addSubview(colorPickerView)
    

    It looks as expected and appears above all my other views, but why can't I interact with it? I seem to be able to highlight text in the UITextView below this subview.

    Simulator Screen Shot - iPhone 11 - 2020-08-16 at 15 48 26

    opened by alamodey 2
  • Create label next to each color

    Create label next to each color

    Hi, I'm considering using IGColorPicker to implement a tag/bookmark feature in my notebook app. The user can choose different colors to identify pages and then filter through pages based on the color later. I want to label each color as per the right screen mockup. Is that achievable with IGColorPicker?

    IMG_5959

    opened by alamodey 0
  • Delegate method not called when deselect color

    Delegate method not called when deselect color

    Hi !

    First, thank you :)

    When I'm deselecting a color, the delegate method is not called. Am I missing something ? This method is only called when changing color selection.

    func colorPickerView(_ colorPickerView: ColorPickerView, didDeselectItemAt indexPath: IndexPath) {
        // A color has been deselected
      }
    

    Thanks for your help !

    opened by thlbaut 0
  • Not working in Child View Controller

    Not working in Child View Controller

    Perfectly working in a View controller. But when that view controller is added as a child view controller in another controller, no delegate function is working.

    opened by bhatti-saqib 1
Releases(0.4.3)
Owner
iGenius
iGenius
SpriteKit Floating Bubble Picker (inspired by Apple Music) 🧲

Magnetic Magnetic is a customizable bubble picker like the Apple Music genre selection. Demo Video $ pod try Magnetic Features Adding/Removing Nodes

Lasha Efremidze 1.4k Jan 6, 2023
Simple and highly customizable iOS tag list view, in Swift.

TagListView Simple and highly customizable iOS tag list view, in Swift. Supports Storyboard, Auto Layout, and @IBDesignable. Usage The most convenient

Ela Workshop 2.5k Jan 5, 2023
A simple, customizable view for efficiently collecting country information in iOS apps.

CountryPickerView CountryPickerView is a simple, customizable view for selecting countries in iOS apps. You can clone/download the repository and run

Kizito Nwose 459 Dec 27, 2022
Modular and customizable Material Design UI components for iOS

Material Components for iOS Material Components for iOS (MDC-iOS) helps developers execute Material Design. Developed by a core team of engineers and

Material Components 4.6k Dec 29, 2022
Customizable CheckBox / RadioButton component for iOS

GDCheckbox An easy to use CheckBox/Radio button component for iOS, with Attributes inspector support. Requirements Xcode 10+ Swift 5 iOS 9+ Installati

Saeid 23 Oct 8, 2022
A minimalistic looking banner library for iOS. It supports multiple customizable kinds of Banner types

A minimalistic looking banner library for iOS. It supports multiple customizable kinds of Banner types

Emre Armagan 12 Oct 10, 2022
Highly customizable Action Sheet Controller with Assets Preview written in Swift

PPAssetsActionController Play with me ▢️ ?? If you want to play with me, just tap here and enjoy! ?? ?? Show me ?? Try me ?? The easiest way to try me

Pavel Pantus 72 Feb 4, 2022
πŸ“Š A customizable gradient progress bar (UIProgressView).

GradientProgressBar A customizable gradient progress bar (UIProgressView). Inspired by iOS 7 Progress Bar from Codepen. Example To run the example pro

Felix M. 490 Dec 16, 2022
RangeSeedSlider provides a customizable range slider like a UISlider.

RangeSeekSlider Overview RangeSeekSlider provides a customizable range slider like a UISlider. This library is based on TomThorpe/TTRangeSlider (Objec

WorldDownTown 644 Dec 12, 2022
An easy to use UI component to help display a signal bar with an added customizable fill animation

TZSignalStrengthView for iOS Introduction TZSignalStrengthView is an easy to use UI component to help display a signal bar with an added customizable

TrianglZ LLC 22 May 14, 2022
Customizable School Timetable Library

JHTimeTable SwiftUI Customizable School TimeTable Library μ„€μΉ˜ Swift Package Manager μ‚¬μš©ν•˜κΈ° JHTimeTableλ·°λ₯Ό μ„ μ–Έν•©λ‹ˆλ‹€. JHTimeTable(lineColor : .secondary,

LeeProgrammer 4 Jan 6, 2023
A customizable Joystick made with SwiftUI

SwiftUIJoystick ??️ A customizable Joystick made with SwiftUI Create your own Base and Thumb/Handle view using SwiftUI Examples ?? Installation Swift

Michaellis 19 Nov 13, 2022
Fully customizable Facebook reactions like control

Reactions is a fully customizable control to give people more ways to share their reaction in a quick and easy way. Requirements β€’ Usage β€’ Installatio

Yannick Loriot 585 Dec 28, 2022
A beautiful radar view to show nearby items (users, restaurants, ...) with ripple animation, fully customizable

HGRippleRadarView Example To run the example project, clone the repo, and run pod install from the Example directory first. This project is inspired b

Hamza Ghazouani 352 Dec 4, 2022
Easy to use, highly customizable gauge view

GDGauge - Customizable Gauge View Requirements Xcode 11+ Swift 5 iOS 9+ Installation Swift Package Manager .package(url: "https://github.com/saeid/GDG

Saeid 74 Dec 5, 2022
The CITPincode package provides a customizable pincode view

The CITPincode package provides a customizable pincode view. It includes an optional resend code button with a built-in cooldown and an optional divider to be placed anywhere between the cells.

Coffee IT 3 Nov 5, 2022
UIStackView replica for iOS 7.x and iOS 8.x

TZStackView A wonderful layout component called the UIStackView was introduced with iOS 9. With this component it is really easy to layout components

Tom van Zummeren 1.2k Oct 10, 2022
Super awesome Swift minion for Core Data (iOS, macOS, tvOS)

⚠️ Since this repository is going to be archived soon, I suggest migrating to NSPersistentContainer instead (available since iOS 10). For other conven

Marko Tadić 306 Sep 23, 2022
A message bar for iOS written in Swift.

Dodo, a message bar for iOS / Swift This is a UI widget for showing text messages in iOS apps. It is useful for showing short messages to the user, so

Evgenii Neumerzhitckii 874 Dec 13, 2022