I want to put a .png image in the middle of the navigation bar instead of the title written in text. Could you please let me know how to do that?
Thanks.
Discussion. Use navigationBarTitle(_:) to set the title of the navigation bar. This modifier only takes effect when this view is inside of and visible within a NavigationView .
Set the navigationItem's titleView
UIImage *image = [UIImage imageNamed:@"image.png"]; self.navigationItem.titleView = [[UIImageView alloc] initWithImage:image];
Swift 4.2
Includes suggested framing/scaling
let image: UIImage = UIImage(named: "image.png")! let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 40, height: 40)) imageView.contentMode = .scaleAspectFit imageView.image = image self.navigationItem.titleView = imageView
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