Search code examples
ioscocoa-touchuiimageuinavigationbar

Navigation bar with UIImage for title


I want to customize my app's look by using a logo image as the navigation bar's title, instead of plain text. When I use this code

let logo = UIImage(named: "logo.png")
self.navigationItem.titleView = logo;

I get the error "UIImage is not convertible to UIView". How can I do this correctly?


Solution

  • Put it inside an UIImageView

    let logo = UIImage(named: "logo.png")
    let imageView = UIImageView(image:logo)
    self.navigationItem.titleView = imageView