How do I add UIImage to center of UINavigationBar?

笑着哭i 提交于 2019-12-21 07:56:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!