UIAlertController in Swift

Balaji Malliswamy
May 30, 2018 · 3 min read

UIAlertController is one of the most basic component of the app development, because using the UIAlertController to get the feedback, confirmation, choose between the options from the user, also we do alerts.

Components

  • Title : The title of the alert.
  • Alert Message : Descriptive text that provides more details about the reason for the alert.
  • Alert Style : Indicating the type of alert to display.
  • Alert Actions : The actions that the user can take in response to the alert or action sheet.
  • Alert TextField : Text field displayed by the alert.

Alert Styles: Alert Or Action Sheet?

When creating your alert controller, you can choose between two options from enum UIAlertControllerStyle

  1. .alert : An alert displayed modally for the app.
  2. .actionSheet : An action sheet displayed in the context of the view controller that presented it.

Ready? Let’s go, 👨‍💻

Simple alert

Simple action sheet

Alert with distractive button

Alert with more than 2 buttons

Alert with UITextField

If you want to validate the input box, add delegate to the UITextField and you can validate as normally we do for others.


"Good software, like wine, takes time" - Joel Spolsky 🍷


Find it a good read?

Recommend this post (by clicking 👏 button) so other people can see it too…
reach me on Twitter Balaji Malliswamy

Swift India

Swift Developer Community in India 🇮🇳

Balaji Malliswamy

Written by

 developer, Chennai & Writer at Swift India https://about.me/balajimalliswamy , https://unsplash.com/@blahji

Swift India

Swift Developer Community in India 🇮🇳

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade