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

# setBackgroundImage(_:for:barMetrics:)

Sets the background image to use for a given bar position and set of metrics.

## Declaration

```swift
func setBackgroundImage(_ backgroundImage: UIImage?, for barPosition: UIBarPosition, barMetrics: UIBarMetrics)
```

## Parameters

- `backgroundImage`: The image to use for the specified location and metrics.
- `barPosition`: The location of the navigation bar.
- `barMetrics`: The metrics of the navigation bar.

## Discussion

Discussion Resizable images will be stretched vertically, if necessary, for a position of UIBarPosition.topAttached.

## See Also

### Changing the background

- [barTintColor](uikit/uinavigationbar/bartintcolor.md)
- [backgroundImage(for:)](uikit/uinavigationbar/backgroundimage(for:).md)
- [setBackgroundImage(_:for:)](uikit/uinavigationbar/setbackgroundimage(_:for:).md)
- [backgroundImage(for:barMetrics:)](uikit/uinavigationbar/backgroundimage(for:barmetrics:).md)
