iOS Developer Library

Developer

UIKit Framework Reference UIPopoverBackgroundView Class Reference

Options
Deployment Target:

On This Page
Language:

UIPopoverBackgroundView

The UIPopoverBackgroundView class provides the background appearance for a popover. This class must be subclassed before it can be used. The implementation of your subclass is responsible for providing the border decoration and arrow for the popover. Subclasses must override all declared properties and methods to provide information about where to lay out the corresponding popover content and arrow. Subclasses must also provide implementations for all methods of the UIPopoverBackgroundViewMethods protocol.

Subclassing Notes

Your subclass is responsible for providing the background visual styling of the popover, which includes the arrow and appropriately styled border. The popover controller places the actual popover content on top of your background view to finish the popover’s presentation.

The background contents of your view should be based on stretchable images. Because the popover is animated into place (and may require animated transitions), using images is the only way to ensure that the animations are smooth and not jittery. By creating images that can be stretched at appropriate places, your popover can still be resized and adjusted as needed. You can then incorporate those images using UIImageView subviews or Core Animation layers. When the size of the popover changes (perhaps to accommodate the keyboard), all you have to do is adjust the frame rectangles of your embedded image views.

In addition to providing the background content, your subclass must implement the arrowOffset and arrowDirection properties and the methods in the UIPopoverBackgroundViewMethods protocol. The popover controller uses these methods and properties to get and set information related to your background view. The protocol methods are called once and the values you return should never change. However, the values in the arrowOffset and arrowDirection properties can change while your popover is on the screen, so your setter methods should call setNeedsLayout when that happens to update the background image views or layers.

To create a stretchable image, use the resizableImageWithCapInsets: method of UIImage.

Inheritance


Import Statement


Swift

import UIKit

Objective-C

@import UIKit;

Availability


Available in iOS 5.0 and later.
  • The distance (measured in points) from the center of the view to the center line of the arrow.

    Declaration

    Swift

    var arrowOffset: CGFloat

    Objective-C

    @property(nonatomic, readwrite) CGFloat arrowOffset

    Discussion

    The default implementation of this method raises an exception. You must override it and implement the appropriate setter and getter methods yourself. Your methods must not call super.

    Use this value during layout to get the position of the arrow. In your setter method, you should similarly initiate an update to your view’s layout so that you can reposition your stretchable images accordingly.

    Offsets are always specified relative to the center of your view object. Adding the offset value to the center value of the given axis yields the required location for the arrow. Thus, for an arrow pointing up or down, a negative offset moves the arrow toward the left edge of the view. For an arrow pointing left or right, a negative offset moves the arrow toward the top of the view.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 5.0 and later.

  • The direction in which the popover arrow is pointing.

    Declaration

    Swift

    var arrowDirection: UIPopoverArrowDirection

    Objective-C

    @property(nonatomic, readwrite) UIPopoverArrowDirection arrowDirection

    Discussion

    The default implementation of this method raises an exception. You must override it and implement the appropriate setter and getter methods yourself. Your methods must not call super.

    You should use this value during layout to configure the images to use for your view’s content. In your setter method, you should update to your view’s content and potentially update the layout as well.

    Use this value to determine which stretchable images to use for your view. Normally, you would have different sets of images depending on whether the arrow was pointing up, down, left, or right. (You could also use the same image for up and down, or left and right, and use a transform to flip the images so that they point in the appropriate direction.) The popover controller sets this value prior to displaying the popover initially, and it may change the value after your popover is displayed on screen.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 5.0 and later.

  • Determines whether the default content appearance should be used for the popover.

    Declaration

    Swift

    class func wantsDefaultContentAppearance() -> Bool

    Objective-C

    + (BOOL)wantsDefaultContentAppearance

    Discussion

    This method may be overridden to prevent the drawing of the content inset and drop shadow inside the popover. The default implementation of this method returns YEStrue, which means that the content inset and drop shadow will be drawn. Overriding this method simply means implementing it to return NOfalse, which would mean that the content inset and drop shadow will not be drawn.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later.