Skip to content

Easily adaptable action sheet supporting custom views as buttons

License

Notifications You must be signed in to change notification settings

ubergrape/AFMActionSheet

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.addAction(action)
self.presentViewController(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.setupTranstioningDelegate(myCustomTransitioningDelegate)

Action controls

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

actionSheet.addAction(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.addCancelAction(action)

To use custom views as action controls just pass the view with action to addAction or addCancelAction method

actionSheet.addAction(action, control: myCustomControl)
actionSheet.addCancelAction(action, control: 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.addTitleView(myCustomTitleView)

or to set a default UILabel with a text

actionSheet.addTitle("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.

About

Easily adaptable action sheet supporting custom views as buttons

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 95.2%
  • Ruby 4.8%