Welcome to the third and last part of this session, where we’ve created some useful custom views. We’ve implemented a custom text input view, a custom accordion menu, and now we’re going to build a simple custom alert view. Read on!
The custom Alert View is going to be an alternative, simple, and nice alert view that will serve our need to display simple messages to the user. It will mainly consist of the following parts.
- A label upon which the message will appear.
- A toolbar below the label.
- An okay button on the right side of the toolbar.
- A cancel button on the left side of the toolbar.
The above will reside together into a UIView, and the view will be contained into the main view of the view controller that we’ll build for the purpose of this custom alert view.
The main view of the view controller is going to be semi-transparent, which will prevent users from tapping on anything else in the background while the alert view is up.
Furthermore, the alert view will slide in from the top side of the screen when it’s about to appear, and it’ll slide out with the reverse move when it’s about to go offscreen. It’ll contain two buttons, an okay button and a cancel button. They can be visible or not depending on the needs of the message about to appear.