0

I have set an backgroundImage for my navigationbar. This works fine. But I would like to have the navigationbar height to be adjusted to the background image. At the moment the width of the background images is also not set according to the screen size.

I tried setting the height of the navigationbar like described here. This shows a bigger navigationbar for like a second but then it shrinks to its default size again.

Does anyone know how to achieve what I want? Here is an example of what I want to achieve: image

progNewbie
  • 4,362
  • 9
  • 48
  • 107

2 Answers2

1

Apple Documentation:

It is permissible to customize the appearance of the navigation bar using the methods and properties of the UINavigationBar class but you must never change its frame, bounds, or alpha values or modify its view hierarchy directly.

To achieve the effect seen in the image you tagged, they are most likely using a collection view to layout their data and that image is part of the collection view's header. They made the navigation bar background color clear, but the image is definitely not part of the navigation bar itself.

Apple recommends to never change the frame of a navigation bar manually because it messes with the layout code of its subviews and animation methods.

You could either subclass the navigation bar and attempt to create something similar, or go the easier route and make the navigation bar clear (UIColor(white: 0, alpha: 1) not .clear otherwise it might show up incorrectly) and have an underlying view display the image (e.x. a collection view whos header extends to the top of the view controller).

This will allow you to adjust the image height and width freely without subclassing the navigation bar, and creating potential bugs.

Community
  • 1
  • 1
Nathan
  • 949
  • 8
  • 19
0

You can make custom NavigationBar class.
It can be help you
https://developer.apple.com/library/archive/samplecode/NavBar/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007418-Intro-DontLinkElementID_2

Eysner
  • 584
  • 4
  • 15