Skip to content

Modeso/ModesoActionOverlay

Repository files navigation

ModesoActionOverlay

Build Status CocoaPods Compatible Carthage Compatible Platform Twitter

ModesoActionOverlay is a "more options" button library written in Swift. It opens an overlay view with dynamic number of action buttons (1 to 5 buttons) with transition animation depending on Anton Aheichanka's design.

Requirements

  • iOS 8.0+
  • Xcode 8.1+
  • Swift 3.0+

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To integrate ModesoActionOverlay into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'ModesoActionOverlay', :git => 'https://github.com/Modeso/ModesoActionOverlay.git'
end

Then, run the following command:

$ pod install

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate ModesoActionOverlay into your Xcode project using Carthage, specify it in your Cartfile:

github "Modeso/ModesoActionOverlay" "master"

Run carthage update --platform iOS to build the framework and drag the built ModesoActionOverlay.framework into your Xcode project.

Manually

If you prefer not to use either of the aforementioned dependency managers, you can integrate ModesoActionOverlay into your project manually.

Simply download zip folder and unarchieve it, drag the directory Sources/ into your project navigation and that's it.


Usage

Xib file

Xib

  • Add your action button.
  • Change the class of the added button to ActionButton
  • Set target view via outlet targetView

Code

In your ViewController.swift class import ModesoActionOverlay

import ModesoActionOverlay

Add an outlet of your added button in your ViewController.swift class

@IBOutlet weak var actionButton: ActionButton!

Define a new OverlayTransition instance.

var overlayTransition: OverlayTransition!

Assign it in viewDidLoad method

    override func viewDidLoad() {
        super.viewDidLoad()

        transition = ModesoOverlayTransition()
    }

Then, set necessary parameters for actionButton

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        actionButton.parentViewController = self
        actionButton.targetView = yourTargetView
        actionButton.overlayViewDelegate = self
        actionButton.overlayButtonsNumber = 3
        actionButton.overlayButtonsIds = [1, 2, 3]
        actionButton.overlayButtonsImages = ["camera-icon", "share-icon", "cloud-icon"]
        actionButton.closeButtonIcon = "delete-icon"
        actionButton.duration = 0.5
        actionButton.transition = transition
    }

parentViewController: The view controller which contains your action button and responsible for presenting the modal view controller which contains the options buttons.
targetView: Your overlayed view.
overlayViewDelegate: OverlayViewDelegate handle showin action button after dismissing the modal view controller by calling showActionButton() method and handle actions of options buttons by calling buttonClicked(id: Int) method.
overlayButtonsNumber: The number of the options buttons inside the modal view controller 1 to 5 buttons.
overlayButtonsIds: Array of integers represents the id of each button.
overlayButtonsImages: Array of strings represents buttons icons' names.
duration: Repesent the animation duration.
transition: ModesoOverlayTransition isntance which contains all transition methods

Then, you can also handle UIViewControllerTransitioningDelegate methods if needed.

//MARK:- UIViewControllerTransitioningDelegate methods
extension ViewController: UIViewControllerTransitioningDelegate {
    
    func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        return transition
    }
}

startingPoint: The point which transition animation will start from. overlayViewColor: Color of the overlay view.

Finally, handle OverlayViewDelegate methods

//MARK:- OverlayViewDelegate methods
extension ViewController: OverlayViewDelegate {
    func showActionButton() {
        actionButton.showActionButton()
    }
    func buttonClicked(id: Int) {
        print("buttonID\(id)")
    }
}

Communication

  • If you found a bug, open an issue.
  • If you have a feature request, open an issue.
  • If you want to contribute, submit a pull request.

Credits

ModesoActionOverlay is owned and maintained by Modeso. You can follow them on Twitter at @modeso_ch for project updates and releases.

License

ModesoActionOverlay is released under the MIT license. See LICENSE for details.