MNGradientColorPicker is a color picker for iOS. It allows you to pick gradient colors for your views.
- iOS 13.0 or later
- Xcode 13.0 or later
- Swift 5.0 or later
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.1"))
]
If you prefer not to use dependency managers, you can integrate MNGradientColorPicker into your project manually.
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.
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.
- Mohit Nandwani (@iMohitnandwani)
MNGradientColorPicker is released under the MIT license. See LICENSE for details.