Introduction
Welcome to the documentation for EmAlertController! This framework provides an easy-to-use and customizable way to display alert dialogs in your iOS app. Whether you need to show a simple informational message or prompt the user for input, EmAlertController has got you covered.
Installation
To install EmAlertController in your project, you can use CocoaPods. Simply add the following line to your Podfile
:
“`ruby
pod ‘EmAlertController’, ‘~> X.Y.Z’
“`
Replace X.Y.Z with the latest version of the framework. Then, run the command pod install
in the Terminal.
Usage
Import the Framework
After installing the framework, import it into your class where you want to use EmAlertController:
“`swift
import EmAlertController
“`
Creating an Alert
To create an alert dialog, you first need to initialize an instance of EmAlertController
. You can set the title, message, and preferred style of the alert. For example:
“`swift
let alertController = EmAlertController(title: “Welcome to EmAlertController”,
message: “This is a demo of EmAlertController in action.”,
preferredStyle: .alert)
“`
Adding Actions
Actions allow users to interact with the alert. You can add actions to an alert by creating instances of EmAlertAction
and adding them to the alert controller. Each action has a title and a style, which determines its appearance. For instance:
“`swift
let cancelAction = EmAlertAction(title: “Cancel”, style: .cancel) { _ in
// Handle cancellation
}
let okayAction = EmAlertAction(title: “Okay”, style: .default) { _ in
// Handle okay action
}
alertController.addAction(cancelAction)
alertController.addAction(okayAction)
“`
Presenting the Alert
Once you have created the alert and added all the desired actions, you can present it to the user. Use the present(_:animated:completion:)
method on your view controller to show the alert. For example:
“`swift
present(alertController, animated: true, completion: nil)
“`
Customization
EmAlertController allows for various customization options to match your app’s design and requirements. Here are a few examples:
Alert Styles
- .alert: A standard alert style. Displays the title and message with appropriate styling.
- .actionSheet: An action sheet style. Displays the alert from the bottom of the screen, useful for displaying options or additional actions.
Alert Actions
- .default: The default style, used for actions that perform a standard operation.
- .cancel: Indicates that the action cancels the operation and dismisses the alert.
- .destructive: Indicates that the action might lead to destructive behavior, such as deleting data.
Theming
EmAlertController provides the ability to customize the appearance of your alert using EmAlertAppearance
. You can modify properties like title font, message color, button colors, and more to fit your app’s aesthetic.
“`swift
emAlertController.appearance.titleFont = UIFont(name: “Arial”, size: 20)
emAlertController.appearance.messageColor = .darkGray
“`
Conclusion
Congratulations! You now have a thorough understanding of EmAlertController and how to utilize it in your app. For more information, make sure to check out the official documentation on GitHub.