-2

I want a logo to be present throughout my app. My entire app has an embedded Navigation Controller so I figured that I could set this image in the app delegate like so:

let logo = UIImage(named: "logo")
        let imageView = UIImageView(image:logo)
        UINavigationBar.appearance().topItem?.titleView = imageView

But it doesn't appear to be working. Is there something that I am doing wrong?

user3612986
  • 315
  • 2
  • 7
  • 18
  • Why do you think it is not working? What did you expect to see, what did you see instead? If we have to guess what isn't working then you are unlikely to get useful answers. – Jonah Mar 11 '16 at 20:53
  • You are changing the `titleView` of the `topItem` at a particular moment in time. As soon as you push or pop a view controller from that navigation controller stack the `topItem` will change. – Jonah Mar 11 '16 at 20:55
  • Hey Jonah The image is not displaying at all. – user3612986 Mar 11 '16 at 20:56
  • @Jonah, Thanks Jonah but is there not a way to set a global setting to all Navigation Controllers? I am able to change the background color of it. – user3612986 Mar 11 '16 at 20:58

1 Answers1

1

You cannot achieve this using appearance() API.

Instead, you either have to provide an image view for each controller's navigation item's title view, or you can subclass UINavigationBar to add an image view that will always be there, regardless of what is in the navigation item. Then set all your controllers' titles to nil/empty string.

Léo Natan
  • 56,823
  • 9
  • 150
  • 195