iOS Developer Library

Developer

UIBarPositioning Protocol Reference

Options
Deployment Target:

On This Page
Language:

UIBarPositioning

The UIBarPositioning protocol defines the ways that bars can be positioned on iOS devices. Bars can be positioned at the bottom of their enclosing view, at the top of their enclosing view, or at both the top of their enclosing view and also the top of the screen. In this last case, the bar will abut the status bar displayed by the system. Bars in this position need to have their background extend above their own frame to the top of the screen. This allows the background to show through the status bar.

The classes that implement bars have paired methods to set a background for a given position and set of metrics. These are named similar to the following: backgroundImageForBarPosition:barMetrics: and setBackgroundImage:forBarPosition:barMetrics:. Use these methods to set an appropriate background image for the different possible bar positions and metrics.

Inheritance


Not Applicable

Import Statement


Swift

import UIKit

Objective-C

@import UIKit;

Availability


Available in iOS 7.0 and later.
  • barPosition barPosition Required Property

    The position of the bar. (required)

    Declaration

    Swift

    var barPosition: UIBarPosition { get }

    Objective-C

    @property(nonatomic, readonly) UIBarPosition barPosition

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

  • Constants to specify metrics to use for appearance.

    Declaration

    Swift

    enum UIBarMetrics : Int { case Default case Compact case DefaultPrompt case CompactPrompt }

    Objective-C

    typedef enum : NSInteger { UIBarMetricsDefault, UIBarMetricsCompact, UIBarMetricsDefaultPrompt = 101, UIBarMetricsCompactPrompt, UIBarMetricsLandscapePhone , // Deprecated UIBarMetricsLandscapePhonePrompt , // Deprecated. } UIBarMetrics;

    Constants

    • Default

      UIBarMetricsDefault

      Specifies default metrics for the device.

      Available in iOS 5.0 and later.

    • Compact

      UIBarMetricsCompact

      Specifies metrics when using the phone idiom.

      Available in iOS 8.0 and later.

    • DefaultPrompt

      UIBarMetricsDefaultPrompt

      Specifies default metrics for the device for bars with the prompt property, such as UINavigationBar and UISearchBar.

      Available in iOS 7.0 and later.

    • CompactPrompt

      UIBarMetricsCompactPrompt

      Specifies metrics for bars with the prompt property when using the phone idiom, such as UINavigationBar and UISearchBar.

      Available in iOS 8.0 and later.

    • UIBarMetricsLandscapePhone

      UIBarMetricsLandscapePhone

      Specifies metrics for landscape orientation using the phone idiom.

      Use UIBarMetricsCompact instead.

      Available in iOS 5.0 and later.

      Deprecated in iOS 8.0.

    • UIBarMetricsLandscapePhonePrompt

      UIBarMetricsLandscapePhonePrompt

      Specifies metrics for landscape orientation using the phone idiom for bars with the prompt property, such as UINavigationBar and UISearchBar.

      Use UIBarMetricsCompactPrompt instead.

      Available in iOS 7.0 and later.

      Deprecated in iOS 8.0.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 5.0 and later.

  • Constants to identify the position of a bar.

    Declaration

    Swift

    enum UIBarPosition : Int { case Any case Bottom case Top case TopAttached }

    Objective-C

    typedef enum: NSInteger { UIBarPositionAny = 0, UIBarPositionBottom = 1, UIBarPositionTop = 2, UIBarPositionTopAttached = 3, } UIBarPosition;

    Constants

    • Any

      UIBarPositionAny

      Specifies that the position is unspecified.

      Available in iOS 7.0 and later.

    • Bottom

      UIBarPositionBottom

      Specifies that the bar is at the bottom of its containing view.

      The system uses this as a hint to draw directional decoration accordingly. For example, any shadow would be drawn above the bar.

      Available in iOS 7.0 and later.

    • Top

      UIBarPositionTop

      Specifies that the bar is at the top of its containing view.

      The system uses this as a hint to draw directional decoration accordingly. For example, any shadow would be drawn below the bar.

      Instances of UIToolbar do not appear with this position on iPhone, but they can on iPad.

      Available in iOS 7.0 and later.

    • TopAttached

      UIBarPositionTopAttached

      Specifies that the bar is at the top of the screen, as well as its containing view.

      Bars with this position draw their background extended upwards, allowing their background content to show through the status bar.

      Available in iOS 7.0 and later.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.