Sheeeeeeeeet is a Swift library for creating custom action sheets. It comes with many built-in components and can be extended with your own custom components.
Sheeeeeeeeet's action sheets can be styled to look like a UIAlertController
or
a lot different. You can also customize how they are presented and dismissed.
To install Sheeeeeeeeet with CocoaPods, add this to your Podfile
:
pod 'Sheeeeeeeeet'
To install Sheeeeeeeeet with Carthage, add this to your Cartfile
:
github "danielsaidi/Sheeeeeeeeet"
To add Sheeeeeeeeet
to your app without Carthage or CocoaPods, clone this repo
and place it somewhere on disk, then add Sheeeeeeeeet.xcodeproj
to the project
and add Sheeeeeeeeet.framework
as an embedded app binary and target dependency.
The most basic way to create an action sheet, is to specify items and the select action, like this:
let title = ActionSheetTitle(title: "Select a value type")
let item1 = ActionSheetItem(title: "Int", value: 1)
let item2 = ActionSheetItem(title: "String", value: "Hi!")
let item3 = ActionSheetItem(title: "Car", value: Car())
let button = ActionSheetOkButton(title: "OK")
let items = [title, item1, item2, item3, button]
let sheet = ActionSheet(items: items) { sheet, item in
if let value = item.value as? Int { print("You selected an int: \(value)") }
if let value = item.value as? String { print("You selected a string: \(value)") }
if let value = item.value as? Car { print("You selected a car") }
if item.isOkButton { print("You tapped the OK button") }
}
To present the action sheet, just call any of its present
functions, like this:
sheet.present(in: self, from: view, completion: ...) // or
sheet.present(in: self, from: barButtonItem, completion: ...)
The from
view is optional and is only used if the action sheet it presented in
a popover.
You can use Sheeeeeeeeet to create really basic action sheets like the one above, as well as very competent and self-contained ones. The one above is just a start. When you have the basics under control, check out this example to see how you can take things one step further.
Sheeeeeeeeet comes with many built-in item types, e.g. regular items, single and multi-select items, links, collection-based items, custom items, buttons, titles etc. For a complete list of item types, click here.
Sheeeeeeeeet lets you fully customize the appearances of action sheets and their views and items. You can change fonts, colors and images as well as item heights and even more stuff. For a complete guide, click here.
If you require a created action sheet instance to resolve which items to present
(very common when you subclass ActionSheet
), just create a sheet with no items
then call setup(with:)
once its created.
This project contains an example app that demonstrates basic and advanced action
sheet, as well as how to handle subclassing, appearances etc. Before you can run
it you must install Carthage and run carthage update --platform iOS
.
You can then open the project and try out the different sheets and item types.
I hope you like this library. Feel free to reach out if you have questions or if you want to contribute in any way:
- E-mail: [email protected]
- Twitter: @danielsaidi
- Web site: danielsaidi.com
Sheeeeeeeeet is available under the MIT license. See LICENSE file for more info.