---
title: "#271: Beautiful Alerts with PMAlertController ⚠️"
url: https://littlebitesofcocoa.com/271-beautiful-alerts-with-pmalertcontroller
author: Jake Marsh
date: 2016-10-03
published: 2016-10-03
topics: ["UIKit","Libraries"]
description: "Alerts have been around since iOS was iPhone OS. First in the form of UIAlertView, and now through UIAlertController (Bite #44)."
---

# #271: Beautiful Alerts with PMAlertController ⚠️

By Jake Marsh, October 3, 2016. HTML: https://littlebitesofcocoa.com/271-beautiful-alerts-with-pmalertcontroller

_Alerts_ have been around since **iOS** was [iPhone OS](https://en.wikipedia.org/wiki/IPhone_OS_1). First in the form of _UIAlertView_, and now through _UIAlertController_ ([Bite #44](https://littlebitesofcocoa.com/44-uialertcontroller)). The built-in system _alerts_ work great, but sometimes we want something fancier 🎩.  Today we'll check out [PMAlertController](https://github.com/Codeido/PMAlertController) from [Paolo Musolino](https://github.com/Codeido), a library that allows us to easily display great looking _alerts_ in our **app**. Let's take a look.

[PMAlertController](https://github.com/Codeido/PMAlertController) is essentially a fancier replacement for the styles that **UIKit's** _UIAlertController_ already provides.

[PMAlertController](https://github.com/Codeido/PMAlertController) two styles of _alerts_: <i>"Alert"</i> and <i>"Walkthrough"</i>. 

The <i>"Alert"</i> Style is 270 points wide (matching the system's _alerts_):

<img src="https://media.littlebitesofcocoa.com/271-1.png" style="max-width: 684px;" />

The <i>"Walkthrough"</i> Style is almost the full **width** of the screen and is appropriate for more in-depth _alerts_/dialogs (such as those for explaining why our app is requesting permission for some of the user's data):

<img src="https://media.littlebitesofcocoa.com/271-2.png" style="max-width: 684px;" />

Using [PMAlertController](https://github.com/Codeido/PMAlertController) is <i>almost</i> just like `UIAlertController`.

We're given a **title**, **description** and **image** to work with:

``` swift
let alertVC = PMAlertController(
  title: "Locate your device", 
  description: "Enables access to your...",
  image: UIImage(named: "flag.png"),
  style: .alert
)

alertVC.addAction(PMAlertAction(
  title: "Cancel", style: .cancel,
  action: { in }
))

alertVC.addAction(PMAlertAction(
  title: "Allow", style: .default,
  action: { in }
))

present(alertVC, animated: true, completion: nil)
```

We instantiate the **view controller**, add some **actions** (each with their own **closure** handler that will be called when the **action** is tapped), and present it.

Neat!

Libraries like [PMAlertController](https://github.com/Codeido/PMAlertController) can help us easily add some polish to our **apps**, but they can also be a great way to learn about creating custom controls in general. 

Learn more about [PMAlertController](https://github.com/Codeido/PMAlertController) at [git.io/pmalert](http://pmalert)

<p></p>
