Insert a image in UINavigationBar instead of text

女生的网名这么多〃 提交于 2019-12-13 08:58:00

问题


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!


回答1:


UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yourImage"]];
self.navigationItem.titleView = imageView;



回答2:


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?



来源:https://stackoverflow.com/questions/12099919/insert-a-image-in-uinavigationbar-instead-of-text

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