<!--
{
  "availability" : [
    "iOS: 7.0.0 -",
    "iPadOS: 7.0.0 -",
    "macCatalyst: 13.1.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UISearchBar/backgroundImage(for:barMetrics:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UISearchBar(im)backgroundImageForBarPosition:barMetrics:"
  },
  "title" : "backgroundImage(for:barMetrics:)"
}
-->

# backgroundImage(for:barMetrics:)

Returns the image used for the background in a given position and with given metrics.

```
func backgroundImage(for barPosition: UIBarPosition, barMetrics: UIBarMetrics) -> UIImage?
```

## Parameters

`barPosition`

A bar position constant.

`barMetrics`

A bar metrics constant.

## Return Value

The image used for the search bar background in the position specified by `barPosition` and with the metrics specified by `barMetrics`.

## Discussion

The default value is `nil`.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)