Swiftuna is a decorator library that lets any view have a cool swipe-to-reveal options menu.
The example's source code can be found in the SwiftunaExample project.
Add this to your Podfile:
pod 'Swiftuna', '~> 0.0.4'
- Add this repository as a git submodule of your project. (optional)
- Once you have downloaded the source, add the
Swiftuna.xcodeproj
as a subproject of your main project. - In your main project's General tab, add the
Swiftuna.framework
as an embedded framework.
Then, to use, import the Swiftuna
framework:
import Swiftuna
In order to decorate a view, the first thing to do is to instantiate a Swiftuna
instance, which is the main decorator class. This class is in charge of doing all the configuration, so any custom attributes must be configured here. The configuration of each option in the menu is done separately in the SwiftunaOption
class.
First, define an array of SwiftunaOptions
to use:
let options = [
SwiftunaOption(image: UIImage(named: "Up")!),
SwiftunaOption(image: UIImage(named: "Down")!)
]
Each option is initialized with an image, which is what will be displayed in the menu. You can additionally change the value of the size
property in each SwiftunaOption
object.
The next step is to attach the menu to a view. The short version:
Swiftuna(targetView: anyView, options: options).attach()
If you want to customize the menu a bit, do it before the configuration is attached:
let swiftuna = Swiftuna(targetView: anyView, options: options)
swiftuna.optionsSpacing = 20
swiftuna.backgroundViewColor = UIColor.whiteColor()
swiftuna.attach()
In order to react to certain events (for example, when an option is selected), the listening class must implement the SwiftunaDelegate
protocol:
class MainController: SwiftunaDelegate {
...
let swiftuna = Swiftuna(targetView: anyView, options: options)
swiftuna.delegate = self
Then that class must implement the following method:
func swiftuna(swiftuna: Swiftuna, didSelectOption option: SwiftunaOption, index: Int)
And optionally implement:
func swiftuna(swiftuna : Swiftuna, shouldDismissAfterSelectionOfOption option : SwiftunaOption, index : Int) -> Bool
Comments and suggestions much welcome
Kevin Wong, @kevinwl02
Code distributed under the MIT license