UIActionSheet
A view that presents a set of alternatives for how to proceed with a task.
Declaration
@MainActor class UIActionSheetOverview
In apps that target versions of iOS prior to iOS 8, use the UIActionSheet class to present the user with a set of alternatives for how to proceed with a given task. You can also use action sheets to prompt the user to confirm a potentially dangerous action. The action sheet contains an optional title and one or more buttons, each of which corresponds to an action to take.
Use the properties and methods of this class to configure the action sheet’s message, style, and buttons before presenting it. You should also assign a delegate to your action sheet. Your delegate object is responsible for performing the action associated with any buttons when they’re tapped and should conform to the UIActionSheetDelegate protocol. For more information about implementing the methods of the delegate, see UIActionSheetDelegate.
You can present an action sheet from a toolbar, tab bar, button bar item, or from a view. This class takes the starting view and current platform into account when determining how to present the action sheet. For applications running on iPhone and iPod touch devices, the action sheet typically slides up from the bottom of the window that owns the view. For applications running on iPad devices, the action sheet is typically displayed in a popover that’s anchored to the starting view in an appropriate way. Taps outside of the popover automatically dismiss the action sheet, as do taps within any custom buttons. You can also dismiss it programmatically.
When presenting an action sheet on an iPad, there are times when you shouldn’t include a cancel button. If you’re presenting just the action sheet, the system displays the action sheet inside a popover without using an animation. Because taps outside the popover dismiss the action sheet without selecting an item, this results in a default way to cancel the sheet. Including a cancel button would therefore only cause confusion. However, if you have an existing popover and are displaying an action sheet on top of other content using an animation, a cancel button is still appropriate. For more information, see iOS Human Interface Guidelines.
Subclassing notes
UIActionSheet isn’t designed to be subclassed, nor should you add views to its hierarchy. If you need to present a sheet with more customization than provided by the UIActionSheet API, you can create your own and present it modally with present(_:animated:completion:).
Topics
Creating action sheets
init(title:delegate:cancelButtonTitle:destructiveButtonTitle:otherButtonTitles:_:)init(title:delegate:cancelButtonTitle:destructiveButtonTitle:)
Setting properties
Configuring buttons
addButton(withTitle:)numberOfButtonsbuttonTitle(at:)cancelButtonIndexdestructiveButtonIndexfirstOtherButtonIndex
Presenting the action sheet
Dismissing the action sheet
Constants
See Also
Deprecated classes
UIAlertViewUIDocumentMenuViewControllerUILocalNotificationUIMenuControllerUIMenuItemUIMutableUserNotificationActionUIMutableUserNotificationCategoryUIPopoverControllerUIPreviewActionUIPreviewActionGroupUISearchDisplayControllerUIStoryboardPopoverSegueUIWebViewUIUserNotificationActionUIUserNotificationCategory