I am using a custom title view for a UINavigationBar with the following code:
// Set a label to the nav bar
THLabel *titleLabel = [[THLabel alloc] init];
tit
What worked for me was to create a variable in the view controller that holds your desired title view then initialize it in viewDidLoad. Then you can set that view to the self.navigationItem.titleView in viewWillAppear and it should display properly. No need for setting autoResizeMask, or rightBarButtons, etc.
Example:
class ViewController {
var myTitleImage: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
myTitleImage = UIImageView(frame: CGRect(x: 0, y: 0, width: 25, height: 25))
myTitleImage.contentMode = .scaleAspectFit
myTitleImage.image = #imageLiteral(resourceName: "my_title_image")
// etc...
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.navigationItem.titleView = self.myTitleImage
}
}