问题
My problem is that I have an image with width = 44 and height = 44. This method didn't work properly.
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"image_44.png"] forBarMetrics:UIBarMetricsDefault];
How do I add an UIImage to center of an UINavigationBar?
回答1:
Try this:
UIImageView *titleView = [[UIImageView alloc] initWithImage:myUIImage];
[self.navigationItem setTitleView:titleView];
回答2:
Using Swift :
var titleView = UIImageView(image: UIImage(named: "nameOfTheImage.ext"))
self.navigationItem.titleView = titleView
来源:https://stackoverflow.com/questions/8506679/how-do-i-add-uiimage-to-center-of-uinavigationbar