I want to add an image to the navigationBar. Ive used
[[UINavigationBar appearance] addSubview:logoImage];
it seems to work with iOS 7 but does not work with iOS 8, can anybody please explain why this is happening, and what is the alternate way to add an imageView on navbar in iOS 8?
Calling [[UINavigationBar appearance]
returns an appearance proxy for the receiver class. The addSubview:
method is not tagged as UI_APPEARANCE_SELECTOR
. One major downside to UIAppearance's proxy approach is that it's difficult to know which selectors are compatible.
This article explains it a bit better: http://nshipster.com/uiappearance/
And this link https://gist.github.com/mattt/5135521 from the article, shows the methods that are tagged as UI_APPEARANCE_SELECTOR
in iOS 7.
You should subclass UINavigationBar
and call [[UINavigationController alloc] initWithNavigationBarClass:toolBarClass:]
. Pass your new navigation bar subclass as the first parameter and nil as the second parameter to use the standard UIToolbar
. In your subclass, add the image just like you are doing.
Another possibility that may work is getting the navigation bar of your navigation controller and adding the sub view there, like this:
[self.navigationController.navigationBar addSubview:logoImage]
. This may work, but creating your own subclass will definitely give you more flexibility.