Suppose you want to show the image to the navigation bar in place navigation title.And it is useful when you want to show your application name in the UINavigationBar . Firstly, you have to create the object of UIImageView then you have to assign an image to the UIImageView object. After assigning object to the UIImageView, then you have to assign that object to the UINavigationBar titleView . Here is the example setting image in UINavigationBar :-
let img = UIImage(named: "logo.jpg")!
let imgView = UIImageView(frame: CGRect(x: CGFloat(0), y: CGFloat(0), width: CGFloat(150), height: CGFloat(50)))
imgView.image = img
imgView.contentMode = .scaleAspectFit
imgView.clipsToBounds = true
self.navigationItem.titleView = imgView
Be the first to comment.