Swiftuna 0.0.4

Swiftuna 0.0.4

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Aug 2017
SwiftSwift Version 3.0
SPMSupports SPM

Maintained by Kevin Wong.



Swiftuna 0.0.4

  • By
  • Kevin Wong

SwiftunaLogo

Swiftuna is a decorator library that lets any view have a cool swipe-to-reveal options menu.

Example

Swiftuna

The example’s source code can be found in the SwiftunaExample project.

Installation

Manual installation:

  1. Add this repository as a git submodule of your project. (optional)
  2. Once you have downloaded the source, add the Swiftuna.xcodeproj as a subproject of your main project.
  3. In your main project’s General tab, add the Swiftuna.framework as an embedded framework.

Then, to use, import the Swiftuna framework:

import Swiftuna

Usage

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.

Adding the menu

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()

Reacting to events

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

Author

Comments and suggestions much welcome

Kevin Wong, @kevinwl02

License

Code distributed under the MIT license