iOS 11 iPhone X UINavigationbar background image too small

I had a problem in one of my apps, that the background image I set, was too small for the new iPhone X.
So I tried a few things, but nothing worked. For example you could add a taller @3x background image, but then it would be clipped on an iPhone 8 Plus for example.

Finally I found a working solution for swift 3.2. (It should also work in swift 4)

Code:

On the left side is a iPhone 8 Plus simulator and on the right side is the iPhone X simulator.

Before:
iPhone X uinavigationbar background image too small
After:
iPhone X uinavigationbar background image scalled
As you can see now the background image scales properly.

Suchbegriffe:

https://yandex ru/clck/jsredir?from=yandex ru;search;web;;&text=&etext=1827 7shdiQRxW6XzhtRPn3BVF1T2Ka68y2pFKn3EZA47wXw__iq2dqS07kdlJNAA3JfF 4cc06aae2dd89ba1674d2fb35de749c9f0f63979&uuid=&state=_BLhILn4SxNIvvL0W45KSic66uCIg23qh8iRG98qeIXme

Leave a Reply