Skip to content

MNGradientColorPicker is a color picker for iOS. It allows you to pick gradient colors for your views.

License

Notifications You must be signed in to change notification settings

mohitnandwani/MNGradientColorPicker

Repository files navigation

MNGradientColorPicker 🎨

MNGradientColorPicker is a color picker for iOS. It allows you to pick gradient colors for your views.

screenshots

Requirements

  • iOS 13.0 or later
  • Xcode 13.0 or later
  • Swift 5.0 or later

Installation

Swift Package Manager

Swift Package Manager is a tool for managing the distribution of Swift code. It’s integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies.

To integrate MNGradientColorPicker into your Xcode project using Swift Package Manager, add it to the dependencies value of your Package.swift:

dependencies: [
    .package(url: "https://github.com/mohitnandwani/MNGradientColorPicker.git", .upToNextMajor(from: "0.3.0"))
]

Manually

If you prefer not to use dependency managers, you can integrate MNGradientColorPicker into your project manually.

Usage

SwiftUI

import SwiftUI
import MNGradientColorPicker

NavigationView {
    // use `selectedColors` (optional value) to preset selected colors...
    MNGradientColorPickerView(selectedColors: [.red, .green]) { colors in
        // get selected colors here on new selection...
    }
}

Note: Use NavigationView to present Gradient Color Picker for better layout.

You can also view or download SwiftUI example for demo purposes.

UIKit

import UIKit
import MNGradientColorPicker

func presentGradientColorPicker() {
    let gradientColorPickerController = MNGradientColorPickerController()
    gradientColorPickerController.selectedColors = // use this to preset selected colors
    gradientColorPickerController.delegate = self // set delegate to get the selected colors
    let navGradientColorPickerController = UINavigationController(rootViewController: gradientColorPickerController)
    self.present(gradientColorPickerController, animated: true)
}

// Delegation Method to get selected colors
extension ViewController: MNGradientColorPickerControllerDelegate {
    func gradientColorPickerViewController(_ controller: MNGradientColorPickerController, didSelect colors: [UIColor]) {
        guard let layer = selectedColorPreview.layer as? CAGradientLayer
        else { return }
        let cgColors = colors.map { $0.cgColor }
        layer.colors = cgColors
    }
    
    func gradientColorPickerViewControllerDidFinish(_ controller: MNGradientColorPickerController) {
        NSLog("Gradient Color Picker Dismissed")
    }
}

Note: Use UINavigationController to present Gradient Color Picker for better layout.

You can also view or download UIKit example for demo purposes.

Live Demo

My app Subtrack (A Subscription Tracker) is using MNGradientColorPicker for color customisation. You can download it and try it on your multiple devices to check it out.

Credits

License

MNGradientColorPicker is released under the MIT license. See LICENSE for details.

About

MNGradientColorPicker is a color picker for iOS. It allows you to pick gradient colors for your views.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages