Insert a image in UINavigationBar instead of text

2019-09-20 15:01发布

i have this piece of code which permits me to insert a title on the UIbar (if i'm not wrong) of the app.

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(ApplicationDidBecomeActive:) name:UIApplicationDidBecomeActiveNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(goToAlbum) name:@"GetAlbumNotif" object:nil];
self.title = @"Events List";

Can you please give me an orientation to this? Thanks!

2条回答
兄弟一词,经得起流年.
2楼-- · 2019-09-20 15:43
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yourImage"]];
self.navigationItem.titleView = imageView;
查看更多
对你真心纯属浪费
3楼-- · 2019-09-20 15:53

A UIBarButton is inside a NavigationBar. The easiest way is to add a UIBarButton to the NavigationBar in the Interface Builder. After that, you can alter the background with:

[barButton setBackgroundImage:[UIImage imageNamed:@"image.png"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

You can change the appearance of a navigation bar if your deployment target is iOS 5.0 or higher with :

[UINavigationBar appearance] setBackgroundImage:

Or do the old fashion way with subclassing UINavigationBar and override drawInRect. How to do that can be found here: How to add background image on iphone Navigation bar?

查看更多
登录 后发表回答