Simple Alert View written in Swift, which can be used as a UIAlertController replacement.
It supports from iOS 10! It is simple and easily customizable!
Supported alerts and action sheets!
AKAlertController can be used as a UIAlertController.
let alertController = AKAlertController(title: "Title label", message: "Message label", preferredStyle: .alert)
let handler: (AKAlertAction) -> Void = { action in print("\(action.title) pressed" )}
alertController.addAction(AKAlertAction(title: "Default action", style: .default, handler: handler))
alertController.addAction(AKAlertAction(title: "Cancel action", style: .cancel, handler: handler))
alertController.addAction(AKAlertAction(title: "Destructive action", style: .destructive, handler: handler))
// add textfield
alertController.addTextFieldWithConfigurationHandler { textField in
textField.placeholder = "Password"
textField.secureTextEntry = true
}
present(alertController, animated: true, completion: nil)
let actionSheet = AKAlertController(title: "Title label", message: nil, preferredStyle: .actionSheet)
let handler: (AKAlertAction) -> Void = { action in print("\(action.title) pressed" )}
actionSheet.addAction(AKAlertAction(title: "Default action", style: .default, handler: handler))
actionSheet.addAction(AKAlertAction(title: "Cancel action", style: .cancel, handler: handler))
actionSheet.addAction(AKAlertAction(title: "Destructive action", style: .destructive, handler: handler))
present(actionSheet, animated: true, completion: nil)
AKAlertControlle completely repeats the system UIAlertController interface, but with the ability to customize:
- Fonts (Text, Buttons)
- Colors (Overlay, Views, Text, Buttons)
- Sizes
- It is possible to add an image
var appearance = AKAlertControllerAppearance.defaultAppearance()
appearance.titleFont = .systemFont(ofSize: 22)
appearance.titleTextColor = .purple
let alertController = AKAlertController(title: "Title", message: "Message", preferredStyle: .alert, appearance: appearance)
...
...
let cancelAction = AKAlertAction(title: "Cancel", style: .cancel, handler: handler)
cancelAction.bgColor = .black
cancelAction.textColor = .white
cancelAction.icon = UIImage(named: "close")
alertController.addAction(cancelAction)
...
let alertController = AKAlertController(title: "Title label", message: "Message label", headerImage: UIImage(named: "close"), preferredStyle: .alert)
let handler: (AKAlertAction) -> Void = { action in print("\(action.title) pressed" )}
alertController.addAction(AKAlertAction(title: "Default action", style: .default, handler: handler))
alertController.addAction(AKAlertAction(title: "Cancel action", style: .cancel, handler: handler))
alertController.addAction(AKAlertAction(title: "Destructive action", style: .destructive, handler: handler))
present(alertController, animated: true, completion: nil)
To run the example project, clone the repo, and run pod install
from the Example directory first.
- iOS 10.0+
- Swift 5.0+
- Xcode 11+
AKAlertController is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'AKAlertController', '~> 1.1.1'
AKAlertController is available under the MIT license. See the LICENSE file for more info.