Reputation: 7113
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.
Upvotes: 9
Views: 7052
Reputation: 23451
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
Upvotes: 17