- April 27, 2024
- Mins Read
SheetyColors is an action sheet styled color picker for iOS:
UIAlertController
. Simply add buttons to it as you would for any other Action Sheet by defining UIAlertAction
instances. Therefore, it nicely integrates with the look & feel of all other native system dialogs. However, you can also chose to use the color picker it self without an action sheet.NEW: Hex input
RGB, HSB, and Grayscale |
---|
Dark mode support
To get a quick overview, you can checkout the example app on Appetize.io. To run the example project from Xcode, clone the repo, and run pod install
from the Example directory first.
There are currently four different ways to integrate SheetyColors into your apps.
use_frameworks!
target ‘MyApp’ do
pod ‘SheetyColors’
end
dependencies: [
.package(url: “https://github.com/chrs1885/SheetyColors.git”, from: “1.2.1”)
]
github “chrs1885/SheetyColors”
Simply drop SheetyColors.xcodeproj
into your project. Also make sure to add SheetyColors.framework
to your app’s embedded frameworks found in the General tab of your main project.
Creating a SheetyColors picker is as easy as creating a normal .actionSheet
styled UIAlertController
. First, you need to import the library:
import SheetyColors
Next, simply create a SheetyColorsController
instance and add some actions to it:
// Create a SheetyColors view with your configuration
let config = SheetyColorsConfig(alphaEnabled: true, initialColor: color, hapticFeedbackEnabled: true, title: “Create a color”, type: .rgb)
let sheetyColors = SheetyColorsController(withConfig: config)
// Add a button to accept the selected color
let selectAction = UIAlertAction(title: “Save Color”, style: .default, handler: { _ in
self.color = sheetyColors.color
}
sheetyColors.addAction(selectAction)
// Add a cancel button
let cancelAction = UIAlertAction(title: “Cancel”, style: .cancel, handler: nil)
sheetyColors.addAction(cancelAction)
// Now, present it to the user
present(sheetyColors, animated: true, completion: nil)
Please check the documentation for further information on the API.
If you prefer to use the color picker inside a custom view controller, you can do so by creating the picker’s view controller directly:
return SheetyColorsViewFactory.createView(withConfig: config, delegate: myDelegate)
The class of the myDelegate
instance needs to conform to the SheetyColorsDelegate
:
class MyViewController: SheetyColorsDelegate {
…
func didSelectColor(_ color: UIColor) {
self.color = color
}
}
didSelectColor
will be called on any slider change.
With SwiftUI projects the color picker can’t be used inside the action sheet that Apple provides. However, you can embed the view inside your custom view container by using the SheetyColorsView
:
struct ContentView: View {
@State var selectedColor: UIColor = UIColor.white
let config = SheetyColorsConfig(alphaEnabled: true, hapticFeedbackEnabled: true, initialColor: UIColor.red, type: .rgb)
var body: some View {
Text(“Select a color”)
.foregroundColor(Color(self.$selectedColor.wrappedValue))
SheetyColorsView(config: config, color: self.$selectedColor)
}
}
Here’s an example of how creating an action sheet styled color picker with SwiftUI and SheetyColors.
Horizon SDK is a state of the art real-time video recording / photo shooting iOS library. Some of the features ...