Create customizable bottom-half sheets.
- Roadmap
- What's new
- Installation
- Swift Package Manager
CocoaPodsNot available yet for 1.2.0CarthageNot available yet for 1.2.0- Manual installation
- Usage
- SVItems included
- Create custom SVItems
- Contributing
- Create DocC documentation
- Allow UIFont override
- Add support for Xib hosted SVItems
- Add new SVItems
- Dynamic type support
- SVSegmentedControlItem
- SVStepperItem
- SVSpacerItem
To install SnackView library using Swift Package Manager from Xcode select File > Add Package and enter:
https://github.com/lucacasula91/SnackView
If you want to install SnackView manually, just drag Sources folder into your project.
To create a custom SnackView your UIViewController or you NSObject class should conform to to SnackViewDataSource protocol. SnackViewDataSource allows you to specify title bar elements and UI elements that sheet should present.
The first step is to specify the title of you SnackView sheet:
func titleFor(snackView: SnackView) -> String {
return "My Title"
}
Then you can specify the dismission button title. This method can return an Optional string value to hide the dismission button.
- Note: If you pass nil it is up to you to handle manually the SnackView dismission logic.
func cancelTitleFor(snackView: SnackView) -> String? {
return "Cancel"
}
The last part required is the method with which specify the items to show.
func itemsFor(snackView: SnackView) -> [SVItem] {
let descriptionItem = SVDescriptionItem(withDescription: "In this last release of SnackView we...")
let imageItem = SVImageViewItem(withImage: UIImage(named: "what_is_new")!,
andContentMode: .scaleAspectFill)
return [descriptionItem, imageItem]
}
Once conformed to SnackViewDataSource you are ready to present you SnackView sheet:
let snackView = SnackView(with: dataSource)
snackView.show()
Here below an example of SnackView implementation:
class MyCustomClass: UIViewController {
override func viewDidLoad() { }
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
// Present the SnackView
let dataSource = self
SnackView(with: dataSource).show()
}
}
// MARK: - SnackViewDataSource Section
extension MyCustomClass: SnackViewDataSource {
func titleFor(snackView: SnackView) -> String {
return "What's New"
}
func cancelTitleFor(snackView: SnackView) -> String? {
return "Dismiss"
}
func itemsFor(snackView: SnackView) -> [SVItem] {
let descriptionItem = SVDescriptionItem(withDescription: "In this last release of SnackView we...")
let imageItem = SVImageViewItem(withImage: UIImage(named: "what_is_new")!,
andContentMode: .scaleAspectFill)
return [descriptionItem, imageItem]
}
}
SnackView provides some SVItems ready to use, here below the list of some SVItems available:
- SVStepperItem
- SVSliderItem
- SVSegmentedControllerItem
- SVSpacerItem
SVApplicationItem
SVApplicationItem(withIcon: UIImage(named: "AppIcon"),
withTitle: "Ipsum lorem",
andDescription: "Lorem ipsum dolor sit amet...")
SVDescriptionItem
SVDescriptionItem(withDescription: "Lorem ipsum dolor sit amet...")
SVTextFieldItem
SVTextFieldItem(withPlaceholder: "Create Password",
isSecureField: true)
SVDetailTextItem
SVDetailTextItem(withTitle: "Elit amet",
andContent: "Lorem ipsum dolor sit amet...")
SVButtonItem
SVButtonItem(withTitle: "Continue") { /* Button action here */ }
SVSwitchItem
SVSwitchItem(withTitle: "Push Notifications",
andContent: "Activate to stay up to date...") { (isOn) in /* Switch action here */ }
SVLoaderItem
SVLoadingItem(withSize: .large,
andText: "Lorem ipsum dolor sit amet...")
SVImaveViewItem
SVImageViewItem(with: UIImage(named: "hat_is_new")!,
andContentMode: .scaleAspectFill)
Here below an example.
import UIKit
import SnackView
//Create a subclass of SVItem
class SVCustomItem: SVItem {
//Pass all parameters in init method to customize your SVItem
init(withColor color: UIColor) {
super.init()
//Add an UIView
let customView = UIView()
customView.translatesAutoresizingMaskIntoConstraints = false
customView.backgroundColor = color
self.addSubview(customView)
//Add UIView contraints
let vConstraints = NSLayoutConstraint.constraints(withVisualFormat: "V:|-[customView(70)]-|", options: [], metrics: nil, views: ["customView":customView])
let hConstraints = NSLayoutConstraint.constraints(withVisualFormat: "H:|-[customView]-|", options: [], metrics: nil, views: ["customView": customView])
self.addConstraints(vConstraints + hConstraints)
}
required public convenience init?(coder aDecoder: NSCoder) {
self.init(coder: aDecoder)
}
}
If you want to contribute to make SnackView a better framework, submit a pull request.
Please consider to open an issue for the following reasons:
- If you have questions or if you need help using SnackView
- If you found a bug
- If you have some feature request