Anshul Bhatheja
Anshul Bhatheja

Reputation: 693

UINavigationBar Background Image Repeats Itself

I am setting a background image on the uinavigationbar, but the image is repeating itself. I don't want that the image repeats itself. Can anyone help me in this.

Here is the code for setting the background image:

navigationController?.navigationBar.setBackgroundImage(UIImage(named: "Image_Name")), for: .default)

Here is the screenshot of my navigation bar: enter image description here

See the circled portion, there is a line in between and after that line the image starts repeating itself.

Thanks In Advance

Upvotes: 1

Views: 600

Answers (2)

Aatish Molasi
Aatish Molasi

Reputation: 2186

You could try this:

let barImage = yourUIImage.stretchableImage(withLeftCapWidth: 0, topCapHeight: 0)
self.navigationController?.navigationBar.setBackgroundImage(barImage, for: .default)

Upvotes: 0

tailor
tailor

Reputation: 665

Set resizable image with resizing mode. try this code.

let image = //your image
let barImage = image.resizableImage(withCapInsets: .zero, resizingMode: .stretch)
self.navigationController?.navigationBar.setBackgroundImage(barImage, for: .default)

Upvotes: 4

Related Questions