---
title: "setBackgroundImage(_:for:barMetrics:)"
framework: uikit
role: symbol
role_heading: Instance Method
path: "uikit/uibarbuttonitem/setbackgroundimage(_:for:barmetrics:)"
---

# setBackgroundImage(_:for:barMetrics:)

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

## Declaration

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

## Parameters

- `backgroundImage`: The background image for the specified state and metrics.
- `state`: A control state.
- `barMetrics`: Bar metrics.

## Discussion

Discussion For good results, backgroundImage must be a stretchable image.

## See Also

### Customizing the background

- [backgroundVerticalPositionAdjustment(for:)](uikit/uibarbuttonitem/backgroundverticalpositionadjustment(for:).md)
- [setBackgroundVerticalPositionAdjustment(_:for:)](uikit/uibarbuttonitem/setbackgroundverticalpositionadjustment(_:for:).md)
- [backgroundImage(for:barMetrics:)](uikit/uibarbuttonitem/backgroundimage(for:barmetrics:).md)
- [backgroundImage(for:style:barMetrics:)](uikit/uibarbuttonitem/backgroundimage(for:style:barmetrics:).md)
- [setBackgroundImage(_:for:style:barMetrics:)](uikit/uibarbuttonitem/setbackgroundimage(_:for:style:barmetrics:).md)
