Class

UIAlert​View

In apps that run in versions of iOS prior to iOS 8, use the UIAlert​View class to display an alert message to the user. An alert view functions similar to but differs in appearance from an action sheet (an instance of UIAction​Sheet).

Overview

UIAlert​View is deprecated in iOS 8. (Note that UIAlert​View​Delegate is also deprecated.) To create and manage alerts in iOS 8 and later, instead use UIAlert​Controller with a preferred​Style of alert.

Using an Alert View

Use the properties and methods defined in this class to set the title, message, and delegate of an alert view and configure the buttons in apps that run in versions of iOS prior to iOS 8. You must set a delegate if you add custom buttons. The delegate should conform to the UIAlert​View​Delegate protocol. Use the show() method to display an alert view after it is configured.

Subclassing Notes

The UIAlert​View class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified.

Symbols

Creating Alert Views

Setting Properties

var delegate:​ Any​Object?

The receiver’s delegate or nil if it doesn’t have a delegate.

var alert​View​Style:​ UIAlert​View​Style

The kind of alert displayed to the user.

var title:​ String

The string that appears in the receiver’s title bar.

var message:​ String?

Descriptive text that provides more details than the title.

var is​Visible:​ Bool

A Boolean value that indicates whether the receiver is displayed.

Configuring Buttons

func add​Button(with​Title:​ String?)

Adds a button to the receiver with the given title.

var number​Of​Buttons:​ Int

The number of buttons on the alert view.

func button​Title(at:​ Int)

Returns the title of the button at the given index.

func text​Field(at:​ Int)

Returns the text field at the given index

var cancel​Button​Index:​ Int

The index number of the cancel button.

var first​Other​Button​Index:​ Int

The index of the first other button.

Displaying

func show()

Displays the receiver using animation.

Dismissing

func dismiss(with​Clicked​Button​Index:​ Int, animated:​ Bool)

Dismisses the receiver, optionally with animation.