iOS Developer Library

Developer

UIKit Framework Reference UIPopoverController Class Reference

Options
Deployment Target:

On This Page
Language:

UIPopoverController

The UIPopoverController class is used to manage the presentation of content in a popover. You use popovers to present information temporarily. The popover content is layered on top of your existing content and the background is dimmed automatically. The popover remains visible until the user taps outside of the popover window or you explicitly dismiss it. Popover controllers are for use exclusively on iPad devices. Attempting to create one on other devices results in an exception. More...

Inheritance


Import Statement


import UIKit @import UIKit;

Availability


Available in iOS 3.2 and later.
  • Returns an initialized popover controller object.

    Declaration

    Swift

    init(contentViewController viewController: UIViewController)

    Objective-C

    - (instancetype)initWithContentViewController:(UIViewController *)viewController

    Parameters

    viewController

    The view controller for managing the popover’s content. This parameter must not be nil.

    Return Value

    An initialized popover controller object.

    Discussion

    When initializing a popover controller, you must specify the view controller object whose content is to be displayed in the popover. You can change this view controller later by modifying the contentViewController property.

    Import Statement

    import UIKit

    Availability

    Available in iOS 3.2 and later.

  • Displays the popover and anchors it to the specified location in the view.

    Declaration

    Swift

    func presentPopoverFromRect(_ rect: CGRect, inView view: UIView, permittedArrowDirections arrowDirections: UIPopoverArrowDirection, animated animated: Bool)

    Objective-C

    - (void)presentPopoverFromRect:(CGRect)rect inView:(UIView *)view permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections animated:(BOOL)animated

    Parameters

    rect

    The rectangle in view at which to anchor the popover window.

    view

    The view containing the anchor rectangle for the popover.

    arrowDirections

    The arrow directions the popover is permitted to use. You can use this value to force the popover to be positioned on a specific side of the rectangle. However, it is generally better to specify UIPopoverArrowDirectionAny and let the popover decide the best placement. You must not specify UIPopoverArrowDirectionUnknown for this parameter.

    animated

    Specify YEStrue to animate the presentation of the popover or NOfalse to display it immediately.

    Import Statement

    import UIKit

    Availability

    Available in iOS 3.2 and later.

  • Displays the popover and anchors it to the specified bar button item.

    Declaration

    Swift

    func presentPopoverFromBarButtonItem(_ item: UIBarButtonItem, permittedArrowDirections arrowDirections: UIPopoverArrowDirection, animated animated: Bool)

    Objective-C

    - (void)presentPopoverFromBarButtonItem:(UIBarButtonItem *)item permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections animated:(BOOL)animated

    Parameters

    item

    The bar button item on which to anchor the popover.

    arrowDirections

    The arrow directions the popover is permitted to use. You can use this value to force the popover to be positioned on a specific side of the bar button item. However, it is generally better to specify UIPopoverArrowDirectionAny and let the popover decide the best placement. You must not specify UIPopoverArrowDirectionUnknown for this parameter.

    animated

    Specify YEStrue to animate the presentation of the popover or NOfalse to display it immediately.

    Discussion

    When presenting the popover, this method adds the toolbar that owns the button to the popover’s list of passthrough views. Thus, taps in the toolbar result in the action methods of the corresponding toolbar items being called. If you want the popover to be dismissed when a different toolbar item is tapped, you must implement that behavior in your action handler methods.

    Import Statement

    import UIKit

    Availability

    Available in iOS 3.2 and later.

  • Dismisses the popover programmatically.

    Declaration

    Swift

    func dismissPopoverAnimated(_ animated: Bool)

    Objective-C

    - (void)dismissPopoverAnimated:(BOOL)animated

    Parameters

    animated

    Specify YEStrue to animate the dismissal of the popover or NOfalse to dismiss it immediately.

    Discussion

    You can use this method to dismiss the popover programmatically in response to taps inside the popover window. Taps outside of the popover’s contents automatically dismiss the popover.

    Import Statement

    import UIKit

    Availability

    Available in iOS 3.2 and later.

  • The view controller responsible for the content portion of the popover.

    Declaration

    Swift

    var contentViewController: UIViewController

    Objective-C

    @property(nonatomic, retain) UIViewController *contentViewController

    Discussion

    This property is initially set to the view controller passed to the initWithContentViewController: method. You can change the value of this property later to reflect a new set of content. Changing the value of this property swaps the new view controller in for the old one immediately and does not trigger an animation. If you want to animate the change, use the setContentViewController:animated: method instead.

    Import Statement

    import UIKit

    Availability

    Available in iOS 3.2 and later.

  • Sets the view controller responsible for the content portion of the popover.

    Declaration

    Swift

    func setContentViewController(_ viewController: UIViewController, animated animated: Bool)

    Objective-C

    - (void)setContentViewController:(UIViewController *)viewController animated:(BOOL)animated

    Parameters

    viewController

    The new view controller whose content should be displayed by the popover.

    animated

    Specify YEStrue if the change of view controllers should be animated or NOfalse if the change should occur immediately.

    Import Statement

    import UIKit

    Availability

    Available in iOS 3.2 and later.

  • The size of the popover’s content view.

    Declaration

    Swift

    var popoverContentSize: CGSize

    Objective-C

    @property(nonatomic) CGSize popoverContentSize

    Discussion

    This property represents the size of the content view that is managed by the view controller in the contentViewController property. The initial value of this property is set to value in the view controller’s contentSizeForViewInPopover property. Changing the value of this property overrides the default value of the current view controller. The overridden value persists until you assign a new content view controller to the receiver. Thus, if you want to keep your overridden value, you must reassign it after changing the content view controller.

    When changing the value of this property, the width value you specify must be at least 320 points and no more than 600 points. There are no restrictions on the height value. However, both the width and height values you specify may be adjusted to ensure the popup fits on screen and is not covered by the keyboard. If you change the value of this property while the popover is visible, the size change is animated.

    Import Statement

    import UIKit

    Availability

    Available in iOS 3.2 and later.

  • Changes the size of the popover’s content view.

    Declaration

    Swift

    func setPopoverContentSize(_ size: CGSize, animated animated: Bool)

    Objective-C

    - (void)setPopoverContentSize:(CGSize)size animated:(BOOL)animated

    Parameters

    size

    The new size to apply to the content view.

    animated

    Specify YEStrue if you want the change in size to be animated or NOfalse if you want the change to appear immediately.

    Discussion

    When changing the size of the popover’s content, the width value you specify must be at least 320 points and no more than 600 points. There are no restrictions on the height value. However, both the width and height values you specify may be adjusted to ensure the popup fits on screen and is not covered by the keyboard.

    Import Statement

    import UIKit

    Availability

    Available in iOS 3.2 and later.

  • An array of views that the user can interact with while the popover is visible.

    Declaration

    Swift

    var passthroughViews: [AnyObject]?

    Objective-C

    @property(nonatomic, copy) NSArray *passthroughViews

    Discussion

    When a popover is active, interactions with other views are normally disabled until the popover is dismissed. Assigning an array of views to this property allows taps outside of the popover to be handled by the corresponding views.

    Import Statement

    import UIKit

    Availability

    Available in iOS 3.2 and later.

  • A Boolean value indicating whether the popover is currently visible. (read-only)

    Declaration

    Swift

    var popoverVisible: Bool { get }

    Objective-C

    @property(nonatomic, readonly, getter=isPopoverVisible) BOOL popoverVisible

    Discussion

    You must present the popover to make it visible.

    Import Statement

    import UIKit

    Availability

    Available in iOS 3.2 and later.

  • The direction of the popover’s arrow. (read-only)

    Declaration

    Swift

    var popoverArrowDirection: UIPopoverArrowDirection { get }

    Objective-C

    @property(nonatomic, readonly) UIPopoverArrowDirection popoverArrowDirection

    Discussion

    The default value of this property is UIPopoverArrowDirectionUnknown. When you present the popover, the value changes to reflect the actual direction of the arrow being used by the popover. When the popover is subsequently dismissed, the value of this property returns to UIPopoverArrowDirectionUnknown.

    Import Statement

    import UIKit

    Availability

    Available in iOS 3.2 and later.

  • delegate delegate Property

    The delegate you want to receive popover controller messages.

    Declaration

    Swift

    unowned(unsafe) var delegate: UIPopoverControllerDelegate?

    Objective-C

    @property(nonatomic, assign) id< UIPopoverControllerDelegate > delegate

    Discussion

    The popover controller uses its delegate to determine whether it should dismiss the popover and provides a notification when such an event occurs. For more information about the methods you can implement in your delegate, see UIPopoverControllerDelegate Protocol Reference.

    Import Statement

    import UIKit

    Availability

    Available in iOS 3.2 and later.

  • The margins that define the portion of the screen in which it is permissible to display the popover.

    Declaration

    Swift

    var popoverLayoutMargins: UIEdgeInsets

    Objective-C

    @property(nonatomic, readwrite) UIEdgeInsets popoverLayoutMargins

    Discussion

    The edge inset values are measured in points from the edges of the screen, relative to the current device orientation. Thus, the top-edge inset always reflects the top edge of the device from the user’s perspective, which changes depending on whether the user is holding the device in a portrait or landscape orientation. Remember that the device orientation is not always the same as the interface orientation—that is, the orientation of your window and views. Window orientations are typically fixed and view orientations are controlled by the owning view controller. In addition, if the rotation lock option is engaged, the interface does not change orientation at all, even when the device orientation changes.

    The default edge insets are 10 points along each edge. The popover controller automatically subtracts the status bar from the viable area when determining where to display the popover, so you do not need to factor the status bar height into your insets.

    Import Statement

    import UIKit

    Availability

    Available in iOS 5.0 and later.

  • The class to use for displaying the popover background content.

    Declaration

    Swift

    var popoverBackgroundViewClass: AnyClass?

    Objective-C

    @property(nonatomic, readwrite, retain) Class popoverBackgroundViewClass

    Discussion

    The default value of this property is nil, which indicates that the popover controller should use the default popover appearance. Setting this property to a value other than nil causes the popover controller to use the specified class to draw the popover’s background content. The class you specify must be a subclass of UIPopoverBackgroundView.

    Import Statement

    import UIKit

    Availability

    Available in iOS 5.0 and later.

  • The color of the popover’s backdrop view.

    Declaration

    Swift

    @NSCopying var backgroundColor: UIColor?

    Objective-C

    @property(nonatomic, copy) UIColor *backgroundColor

    Discussion

    Use this property to customize the background color of your popover. Changing the value of this property while the popover is visible triggers an animated changeover to the new color. The default value of this property is nil, which corresponds to the default background color.

    Import Statement

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • Constants for specifying the direction of the popover arrow.

    Declaration

    Swift

    struct UIPopoverArrowDirection : RawOptionSetType { init(_ rawValue: UInt) init(rawValue rawValue: UInt) static var Up: UIPopoverArrowDirection { get } static var Down: UIPopoverArrowDirection { get } static var Left: UIPopoverArrowDirection { get } static var Right: UIPopoverArrowDirection { get } static var Any: UIPopoverArrowDirection { get } static var Unknown: UIPopoverArrowDirection { get } }

    Objective-C

    enum { UIPopoverArrowDirectionUp = 1UL << 0, UIPopoverArrowDirectionDown = 1UL << 1, UIPopoverArrowDirectionLeft = 1UL << 2, UIPopoverArrowDirectionRight = 1UL << 3, UIPopoverArrowDirectionAny = UIPopoverArrowDirectionUp | UIPopoverArrowDirectionDown | UIPopoverArrowDirectionLeft | UIPopoverArrowDirectionRight, UIPopoverArrowDirectionUnknown = NSUIntegerMax }; typedef NSUInteger UIPopoverArrowDirection;

    Constants

    • Up

      UIPopoverArrowDirectionUp

      An arrow that points upward.

      Available in iOS 3.2 and later.

    • Down

      UIPopoverArrowDirectionDown

      An arrow that points downward.

      Available in iOS 3.2 and later.

    • Left

      UIPopoverArrowDirectionLeft

      An arrow that points toward the left.

      Available in iOS 3.2 and later.

    • Right

      UIPopoverArrowDirectionRight

      An arrow that points toward the right.

      Available in iOS 3.2 and later.

    • Any

      UIPopoverArrowDirectionAny

      An arrow that points in any direction.

      Available in iOS 3.2 and later.

    • Unknown

      UIPopoverArrowDirectionUnknown

      The status of the arrow is currently unknown.

      Available in iOS 3.2 and later.

    Import Statement

    import UIKit

    Availability

    Available in iOS 3.2 and later.