https://github.com/jjessel/jhtalertcontroller
A custom iOS alert that replaces the stock UIAlertController. Easily style the alert to match your app. Written in Swift for iOS.
https://github.com/jjessel/jhtalertcontroller
alert alertcontroller carthage cocoapods custom ios modal swift uialertcontroller uialertview warning
Last synced: 4 months ago
JSON representation
A custom iOS alert that replaces the stock UIAlertController. Easily style the alert to match your app. Written in Swift for iOS.
- Host: GitHub
- URL: https://github.com/jjessel/jhtalertcontroller
- Owner: jjessel
- License: mit
- Created: 2016-11-17T23:21:09.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2019-07-11T09:48:52.000Z (over 6 years ago)
- Last Synced: 2025-09-16T06:56:05.156Z (4 months ago)
- Topics: alert, alertcontroller, carthage, cocoapods, custom, ios, modal, swift, uialertcontroller, uialertview, warning
- Language: Swift
- Homepage:
- Size: 5.2 MB
- Stars: 58
- Watchers: 3
- Forks: 26
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# JHTAlertController
[](http://cocoapods.org/pods/JHTAlertController)
[](http://cocoapods.org/pods/JHTAlertController/blob/master/LICENSE)
[](http://cocoapods.org/pods/JHTAlertController)
[](https://github.com/Carthage/Carthage)



## Easy to use
JHTAlertController is an easy to use replacement for `UIAlertController`. You can customize the appearance of your alert to match the theme of your app.
```swift
// Setting up an alert with a title and message
let alertController = JHTAlertController(title: "Turtle", message: "In this alert we use a String for the title instead of an image.", preferredStyle: .alert)
// Create the action.
let cancelAction = JHTAlertAction(title: "Cancel", style: .cancel, handler: nil)
// Create an action with a completionl handler.
let okAction = JHTAlertAction(title: "Ok", style: .default) { _ in
print("Do something here!")
}
// Add the actions to the alert.
alertController.addAction(cancelAction)
alertController.addAction(okAction)
// Show the action
present(alertController, animated: true, completion: nil)
```
## Customize the Appearance
* Change Fonts
* Change Colors
* Add Icons
#### Alert
```swift
// Change the background color
alertController.alertBackgroundColor = .black
// Round the corners
alertController.hasRoundedCorners = true
```
#### Title Block
```swift
// Use an image instead of text
alertController.titleImage = UIImage(named: "Turtle")
// If you add an image to the title block, you may need to set restrictTitleViewHeight to true, depending on the image size
// Change the color of the text
alertController.titleTextColor = .black
// Change the font
alertController.titleFont = .systemFont(ofSize: 18)
// Change the title block color
alertController.titleViewBackgroundColor = .black
// Add an icon image to the title block
let alertController = JHTAlertController(title: "Wow!", message: "You can even set an icon for the alert.", preferredStyle: .alert, iconImage: UIImage(named: "TurtleDark"))
```
#### Message
```swift
// Change the font
alertController.messageFont = .systemFont(ofSize: 18)
/ Change thte text color
alertController.messageTextColor = .black
```
#### Button
```swift
// Change the color of the divider
alertController.dividerColor = .black
// Change the color of the button during the creation of the action
let blueAction = JHTAlertAction(title: "Blue", style: .default, bgColor: .blue, handler: nil)
// Change the color for all buttons of a specific action
alertController.setButtonBackgroundColorFor(.default, to: .blue)
// Change the text color for a specific action
alertController.setButtonTextColorFor(.default, to: .white)
// Change the font for a specific action
alertController.setButtonFontFor(.default, to: .systemFont(ofSize: 18))
// Change all action types to a specific color
alertController.setAllButtonBackgroundColors(to: .blue)
```
## Example
To run the example project, clone the repo, and run `pod install` from the Example directory first.
## Requirements
iOS 9.0 and higher
## Installation
### CocoaPods
JHTAlertController is available through [CocoaPods](http://cocoapods.org). To install
it, simply add the following line to your Podfile:
```ruby
pod "JHTAlertController"
```
### Carthage
[Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.
You can install Carthage using Homebrew:
```
$ brew update
$ brew install carthage
```
To add JHTAlertController to your Xcode project using Carthage, update your Cartfile:
```
github "jjessel/JHTAlertController" ~> 0.2.4
```
Run ```carthage update``` to build the framework and drag the built JHTAlertController.framework into your Xcode project.
## Author
Jeremiah Jessel @ Jacuzzi Hot Tubs, LLC
## License
JHTAlertController is available under the MIT license. See the LICENSE file for more info.