Code Monkey home page Code Monkey logo

afmactionsheet's Introduction

AFMActionSheet

CI Status Version License Platform

AFMActionSheet provides a AFMActionSheetController that can be used in places where one would use a UIAlertController, but a customized apperance or custom presentation/dismissal animation is needed. Seeing as how AFMActionSheetController was inspired by UIAlertController, it too supports ActionSheet and Alert styles to make your life even easier.

Action Sheet Example Alert Example

Usage

To create an action sheet with default style and default transition animations:

let actionSheet = AFMActionSheetController()
let action = AFMAction(title: "Action", enabled: true, handler: { (action: AFMAction) -> Void in
    // Do something in handler
}
actionSheet.add(action)
self.present(actionSheet, animated: true, completion: {
    // Do something after completion
})

That's it.

Detailed look

Style

AFMActionSheetController supports two styles: the default action sheet style and alert style. These are set via initializers with ControllertStyle enum (ControllertStyle.actionSheet and ControllertStyle.alert accordingly)

let actionSheet = AFMActionSheetController(style: .actionSheet)
let alert = AFMActionSheetController(style: .alert)

Transitioning animations

To change presentation and dismissal animations, implement a UIViewControllerTransitioningDelegate and pass it to AFMActionSheetController

let actionSheet = AFMActionSheetController(transitioningDelegate: myCustomTransitioningDelegate)

or

actionSheet.setup(myCustomTransitioningDelegate)

Action controls

Action sheet's controls are created by adding AFMAction objects to the controller

actionSheet.add(action)

It is also possible to add actions as "Cancel actions". When using ControllertStyle.ActionSheet style, controls for these actions will be displayed in the bottom "Cancel section".

actionSheet.add(cancelling: action)

To use custom views as action controls just pass the view with action to add(_:with:) or add(cancelling:with:) method

actionSheet.add(action, with: myCustomControl)
actionSheet.add(cancelling: action, with: myCustomControl)

Height of the action control is whatever height passed custom view specifies, but it is possible to specify minimal control height with minControlHeight property.

Title view

Title view is a view that is located on top of the action sheet and works similar to action controls. To set the title view with custom view

actionSheet.add(title: myCustomTitleView)

or to set a default UILabel with a text

actionSheet.add(titleLabelWith: "Title")

Like with action control height, it is possible to specify minimal control height with minTitleHeight property.

Other customizations

There is a number of properties to help further modify the look and behavior of action sheet controller:

  • spacing: Int specifies content's spacing between action controls (default is 4)
  • horizontalMargin: Int specifies spacing from content to controller's top and bottom (default is 16)
  • verticalMargin: Int specifies spacing from content to controller's left and right (default is 16)
  • cornerRadius: Int specifies corner radius of content (default is 10)
  • backgroundColor: UIColor specifies controller's background color (default is blackColor().colorWithAlphaComponent(0.5))
  • spacingColor: UIColor specifies content's spacing color (default is .clearColor())
  • outsideGestureShouldDismiss: Bool specifies whether the click on background outside of controls and title dismisses action sheet (default is true)

Example project

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

iOS 8 and up.

Installation

AFMActionSheet is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "AFMActionSheet"

Contact person

Ilya Alesker, [email protected]

License

AFMActionSheet is available under the MIT license. See the LICENSE file for more info.

afmactionsheet's People

Contributors

alesker avatar karpelcevs avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.