Custom UIAlertController – iOS (Objective-C)

Custom UIAlertController – iOS (Objective-C)

Creating a custom UIAlertController helps you to show a popup in your iOS application whenever you need to show a simple warning/information popup. It is an embedded iOS library and that means you do not need to install any 3rd party library.

A classic popup in mobile applications contains 3 parts: title, content and buttons. You set title according the purpose of the popup, set content as message and set buttons to get action.

Create a Screen

Open your project, create a new and empty ViewController and add a simple button to trigger the popup.

Connect this button to ViewController.m file as IBOutlet by selecting “Assistant Editor” at top-left. Drag button with right-click from view to ViewController.m file.

 Create a Simple AlertController

Then, create a simple UIAlertController with a title, a message and a button.

If you want to add another button, for example a cancel button, just add it like “Ok” button.

Add More Buttons and TextField

You can add more than 2 buttons to your AlertController by repeating add action method.

This is a basic view of UIAlertController in an iOS application. You can customize it, of course. For example, you can change colors, fonts, size or you can add a text field in your popup. Let’s start with adding a text field to our popup. In iOS, UIAlertController has a method to add a textfield into the window and it is very simple as a line of code.

And you can customize it too with…

Customize AlertController

As the last customizing, lets change colors of some views in this popup.

That’s all. Maybe it is not a good idea to change all colors in popup like this example 🙂 Be certain of your colors and app theme in a harmony.

Final Work: Custom AlertController

To get the latest version of popup in this tutorial, see the code below.



©Coffee Break Codes – Custom Alert Controller – iOS (Objective-C)

Leave a comment

Your email address will not be published. Required fields are marked *