ANActionSheetController is a highly customizable UIAlertController replica, looks like built-in action sheet, works on iPad too.
ANActionSheetController can have many actions, a cancel action dedicated from the other actions, and a title and/or message, as the built-in UIAlertController. But the difference is; you can customize -almost– every attributes.
Only required thing is having at least 1 action.
Via modifying the controller's appearence
attribute -or setting from scratch- you can customize these:
shadow
: shadow color, offset, radius and opacitycorner radius
seperator
: The size and color of the space between buttons and (title container and/or cancel button)button seperator
: The size and color of the space between buttons
### Title and Message
title and message title color
title and message title font
title and message background
minimum button height
button title font
button title color
button color
Exceptional buttons, looks different from the others buttons.
minimum button height
button title font
button title color
button color
pod 'ANActionSheetController'
Download the repository
Add ANActionSheetController/Source
folder - or its contents- to your project
Usage is same with the UIAlertController
First, create the controller:
let actionSheetController = ANActionSheetController.init(title: "a title" , message: "a message")
Then add actions:
actionSheetController.addAction(ANActionSheetNormalAction.init(title: "Button 1", handler: nil))
actionSheetController.addAction(ANActionSheetNormalAction.init(title: "Button 2", handler: nil))
If you want to add exceptional actions - different looking actions than others - :
var customButtonAppearence = ANActionSheetAppearence.CustomActionAppearence.init()
customButtonAppearence.font = UIFont.init(name: "IntroRustG-Base2Line", size: 17)!
customButtonAppearence.titleColor = UIColor.red
customButtonAppearence.minimumHeight = 10
actionSheetController.addAction(ANActionSheetCustomAction.init(title: "Custom Action", apperarence: customButtonAppearence, handler: nil))
You can add a cancel button:
action.setCancelAction(title: "Cancel Button")
You can customize the controller; for example:
...
actionSheetController.appearence.actionAppearence.titleColor = UIColor(red:0.929, green:0.922, blue:0.923, alpha: 1.000)
actionSheetController.appearence.actionAppearence.color = UIColor(red:0.69, green:0.714, blue:0.616, alpha: 1.000)
actionSheetController.appearence.buttonSeperatorColor = UIColor.init(red: 0.427, green: 0.498, blue: 0.192, alpha: 1)
...
Or you might create a shared customization:
extension ANActionSheetAppearence {
static var aCustomAppearence: ANActionSheetAppearence = {
var customAppearence = ANActionSheetAppearence.init()
customAppearence.actionAppearence.titleColor = UIColor(red:0.929, green:0.922, blue:0.923, alpha: 1.000)
customAppearence.actionAppearence.color = UIColor(red:0.69, green:0.714, blue:0.616, alpha: 1.000)
customAppearence.buttonSeperatorColor = UIColor.init(red: 0.427, green: 0.498, blue: 0.192, alpha: 1)
... and other customizations ...
return customAppearence
}()
}
....
actionSheetController.appearence = ANActionSheetAppearence.aCustomAppearence
....
Then present it:
myController.present(actionSheetController, animated: true, completion: nil)
- You should set at least 1 action!
- Considering action sheets higher than the screen size (especially on landscape phone screen) I used UIScrollView. If you have a better solution, please open asn issue.
- Due to view hiearchy, background colors you set may not look like as expected. For example; if you set seperator to
blue
and buttonSeperator toclear
, button seperators will be seen asblue
.
If you need help open an issue. If you found a bug, open an issue. If you want to contribute, submit a pull request.
ANActionSheetController is released under the MIT license. See LICENSE for details.