Instance Method

setBackgroundImage(_:for:barMetrics:)

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

Declaration

func setBackgroundImage(_ backgroundImage: UIImage?, for state: UIControl.State, barMetrics: UIBarMetrics)

Parameters

backgroundImage

The background image to use for state and barMetrics.

state

A control state.

barMetrics

Bar metrics.

Discussion

If backgroundImage is an image returned from resizableImage(withCapInsets:), the cap widths are calculated from that information.

If backgroundImage is not an image returned from resizableImage(withCapInsets:), the cap width is calculated by subtracting one from the image's width then dividing by 2. The cap widths are used as the margins for text placement. To adjust the margin, use the margin adjustment methods.

Discussion

For more details, see backgroundImage(for:barMetrics:).

See Also

Customizing Appearance

func backgroundImage(for: UIControl.State, barMetrics: UIBarMetrics) -> UIImage?

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

func dividerImage(forLeftSegmentState: UIControl.State, rightSegmentState: UIControl.State, barMetrics: UIBarMetrics) -> UIImage?

Returns the divider image used for a given combination of left and right segment states and bar metrics.

func setDividerImage(UIImage?, forLeftSegmentState: UIControl.State, rightSegmentState: UIControl.State, barMetrics: UIBarMetrics)

Sets the divider image used for a given combination of left and right segment states and bar metrics.

func titleTextAttributes(for: UIControl.State) -> [NSAttributedString.Key : Any]?

Returns the text attributes of the title for a given control state.

func setTitleTextAttributes([NSAttributedString.Key : Any]?, for: UIControl.State)

Sets the text attributes of the title for a given control state.