Class

UIBar​Button​Item

A bar button item is a button specialized for placement on a UIToolbar or UINavigation​Bar object. It inherits basic button behavior from its abstract superclass, UIBar​Item. The UIBar​Button​Item 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 ([UIBar​Button​Item appearance]) to customize all buttons, or to a specific UIBar​Button​Item instance. You may use customized buttons in standard places in a UINavigation​Item object (back​Bar​Button​Item, left​Bar​Button​Item, right​Bar​Button​Item) 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(custom​View:​ UIView)

Initializes a new item using the specified custom view.

init(image:​ UIImage?, style:​ UIBar​Button​Item​Style, target:​ Any?, action:​ Selector?)

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

init(title:​ String?, style:​ UIBar​Button​Item​Style, target:​ Any?, action:​ Selector?)

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

Getting and Setting Properties

var target:​ Any​Object?

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 possible​Titles:​ Set<String>?

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

var width:​ CGFloat

The width of the item.

var custom​View:​ UIView?

A custom view representing the item.

Customizing Appearance

var tint​Color:​ UIColor?

The tint color to apply to the button item.

func back​Button​Background​Image(for:​ UIControl​State, bar​Metrics:​ UIBar​Metrics)

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

func set​Back​Button​Background​Image(UIImage?, for:​ UIControl​State, bar​Metrics:​ UIBar​Metrics)

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

func back​Button​Title​Position​Adjustment(for:​ UIBar​Metrics)

Returns the back button title offset for given bar metrics.

func back​Button​Background​Vertical​Position​Adjustment(for:​ UIBar​Metrics)

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

func background​Vertical​Position​Adjustment(for:​ UIBar​Metrics)

Returns the background vertical position offset for given bar metrics.

func set​Background​Vertical​Position​Adjustment(CGFloat, for:​ UIBar​Metrics)

Sets the background vertical position offset for given bar metrics.

func background​Image(for:​ UIControl​State, bar​Metrics:​ UIBar​Metrics)

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

func title​Position​Adjustment(for:​ UIBar​Metrics)

Returns the title offset for given bar metrics.

Getting the Shortcuts Group Information

var button​Group:​ UIBar​Button​Item​Group?

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

Constants

UIBar​Button​System​Item

Defines system-supplied images for bar button items.

UIBar​Button​Item​Style

Specifies the style of a item.