Quickly add an image to the navigation bar

I am trying to add an image to the navigation bar:

let image = UIImage(named: "my-image")
navigationItem.titleView = UIImageView(image: image)

      

But nothing happens, what am I doing wrong?

+3


source to share


1 answer


    let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 39, height: 39))
    imageView.contentMode = .ScaleAspectFit
    let image = UIImage(named: "newlogo.jpg")
    imageView.image = image
    navigationItem.titleView = imageView

      



+3


source







All Articles