How can I set the title of a UINavigationBar
to be an image using Swift.
For example, Instagram does the following:
Objective: Find how to set the title of a UINavigationBar
to be an image using Swift.
You can do the following :
var titleView = UIImageView(image: UIImage(named: "nameOfTheImage.ext"))
self.navigationItem.titleView = titleView
To fits the the image in the dimension you want you have to do the follwoing :
var titleView : UIImageView
// set the dimensions you want here
titleView = UIImageView(frame:CGRectMake(0, 0, 50, 70))
// Set how do you want to maintain the aspect
titleView.contentMode = .ScaleAspectFit
titleView.image = UIImage(named: "nameOfTheImage.ext")
self.navigationItem.titleView = titleView
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With