Overview
The SPAlertController library is a customizable and easy-to-use replacement for the UIAlertController class in iOS. It allows developers to present alert and action sheet style dialogs with various customization options.
Installation
To install SPAlertController in your iOS project, follow these steps:
- Manually download the SPAlertController framework from the official GitHub repository or use a package manager like Cocoapods.
- Import the SPAlertController framework into your project.
- Ensure that the framework is linked properly and available in your target configuration.
Usage Guide
To use SPAlertController in your iOS app, follow these steps:
- Create an instance of SPAlertController with the desired style (alert or action sheet).
- Add actions (buttons) to the alert controller using the addAction method.
- Customize the appearance of the alert controller using the various properties and methods available.
- Present the alert controller using the present method.
API Reference
The SPAlertController library provides the following API:
init(style: SPAlertControllerStyle)
: Initializes a new instance of SPAlertController with the specified style.addAction(_ action: SPAlertAction)
: Adds an action (button) to the alert controller.setMessage(_ message: String)
: Sets the message text of the alert controller.setTitle(_ title: String)
: Sets the title text of the alert controller.present(animated: Bool, completion: (() -> Void)? = nil)
: Presents the alert controller modally.
Examples
Here are some examples of SPAlertController usage:
- Creating a basic alert controller:
let alertController = SPAlertController(style: .alert)
alertController.setTitle("Alert Title")
alertController.setMessage("This is an example alert.")
let okAction = SPAlertAction(title: "OK", style: .default)
alertController.addAction(okAction)
alertController.present(animated: true)
let alertController = SPAlertController(style: .actionSheet)
alertController.setTitle("Action Sheet Title")
alertController.setMessage("This is an example action sheet.")
let action1 = SPAlertAction(title: "Action 1", style: .default)
let action2 = SPAlertAction(title: "Action 2", style: .default)
let action3 = SPAlertAction(title: "Action 3", style: .default)
alertController.addAction(action1)
alertController.addAction(action2)
alertController.addAction(action3)
alertController.present(animated: true)