Class

UIBarButtonItem

A bar button item is a button specialized for placement on a UIToolbar or UINavigationBar object. It inherits basic button behavior from its abstract superclass, UIBarItem. The UIBarButtonItem defines additional initialization methods and properties for use on toolbars and navigation bars.

Overview

You typically use Interface Builder to create and configure bar button items.

Customizing Appearance

You use the methods listed in Customizing Appearance to customize the appearance of buttons. You send the setter messages to the appearance proxy ([UIBarButtonItem appearance]) to customize all buttons, or to a specific UIBarButtonItem instance. You may use customized buttons in standard places in a UINavigationItem object (backBarButtonItem, leftBarButtonItem, rightBarButtonItem) or a UIToolbar instance.

In general, you should specify a value for the normal state to be used by other states which don’t have a custom value set. Similarly, when a property is dependent on the bar metrics (on iPhone, in landscape orientation bars have a different height from standard), you should specify a value of default.

For more information about appearance and behavior configuration, see Toolbars.

Symbols

Initializing an Item

init(barButtonSystemItem: UIBarButtonSystemItem, target: Any?, action: Selector?)

Initializes a new item containing the specified system item.

init(customView: UIView)

Initializes a new item using the specified custom view.

init(image: UIImage?, style: UIBarButtonItemStyle, target: Any?, action: Selector?)

Initializes a new item using the specified image and other properties.

init(title: String?, style: UIBarButtonItemStyle, target: Any?, action: Selector?)

Initializes a new item using the specified title and other properties.

Getting and Setting Properties

var target: AnyObject?

The object that receives an action when the item is selected.

var action: Selector?

The selector defining the action message to send to the target object when the user taps this bar button item.

var style: UIBarButtonItemStyle

The style of the item.

var possibleTitles: Set<String>?

The set of possible titles to display on the bar button.

var width: CGFloat

The width of the item.

var customView: UIView?

A custom view representing the item.

Customizing Appearance

var tintColor: UIColor?

The tint color to apply to the button item.

func backButtonBackgroundImage(for: UIControlState, barMetrics: UIBarMetrics)

Returns the back button background image for a given control state and bar metrics.

func setBackButtonBackgroundImage(UIImage?, for: UIControlState, barMetrics: UIBarMetrics)

Sets the back button background image for a given control state and bar metrics

func backButtonTitlePositionAdjustment(for: UIBarMetrics)

Returns the back button title offset for given bar metrics.

func setBackButtonTitlePositionAdjustment(UIOffset, for: UIBarMetrics)

Sets the back button title offset for given bar metrics

func backButtonBackgroundVerticalPositionAdjustment(for: UIBarMetrics)

Returns the back button vertical position offset for given bar metrics.

func setBackButtonBackgroundVerticalPositionAdjustment(CGFloat, for: UIBarMetrics)

Sets the back button vertical position offset for given bar metrics.

func backgroundVerticalPositionAdjustment(for: UIBarMetrics)

Returns the background vertical position offset for given bar metrics.

func setBackgroundVerticalPositionAdjustment(CGFloat, for: UIBarMetrics)

Sets the background vertical position offset for given bar metrics.

func backgroundImage(for: UIControlState, barMetrics: UIBarMetrics)

Returns the background image for a given state and bar metrics.

func setBackgroundImage(UIImage?, for: UIControlState, barMetrics: UIBarMetrics)

Sets the background image for a given state and bar metrics.

func backgroundImage(for: UIControlState, style: UIBarButtonItemStyle, barMetrics: UIBarMetrics)

Returns the background image for the specified state, style, and metrics.

func titlePositionAdjustment(for: UIBarMetrics)

Returns the title offset for given bar metrics.

func setTitlePositionAdjustment(UIOffset, for: UIBarMetrics)

Sets the title offset for given bar metrics.

Getting the Shortcuts Group Information

var buttonGroup: UIBarButtonItemGroup?

The group on the shortcuts bar to which the button belongs.

Constants

UIBarButtonSystemItem

Defines system-supplied images for bar button items.

UIBarButtonItemStyle

Specifies the style of a item.