简体   繁体   中英

How do I add UIImage to center of UINavigationBar?

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 ?

Try this:

UIImageView *titleView = [[UIImageView alloc] initWithImage:myUIImage];
[self.navigationItem setTitleView:titleView];

Using Swift :

var titleView = UIImageView(image: UIImage(named: "nameOfTheImage.ext"))
self.navigationItem.titleView = titleView

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM