I'm currently trying to add an image into the navigation item for one view. In the view's viewDidLoad()
, a function is called with the following code, similar to this post:
let logo = UIImage(named: "Menu_Logo")
let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 122, height: 26))
imageView.contentMode = .scaleAspectFit
imageView.clipsToBounds = true
imageView.image = logo
self.navigationItem.titleView = imageView
Instead of giving me the expected size however, the view ends up looking like this:
Removing the UIImage from the UIImageView makes the view sized correctly like this:
This seems like strange behaviour to me, especially since I did set the content mode to .scaleAspectFit
. Is there something I am forgetting regarding adding an UIImageView
as the navigationItem.titleView
?
On
UINavigationBar
, title view takes its full size, if content is large.