How to add an image to the navigation bar

I want to add an image to the navigation bar. This should be the whole application. It must be added to all navigation controllers.

Any help would be appreciated.

+4
source share
5 answers

Try it,

UINavigationBar *navBar = self.navigationController.navigationBar; UIImage *image = [UIImage imageNamed:@"image.png"]; [navBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault]; 
+4
source

You can add image below.

 UIImage *image = [UIImage imageNamed: @"yourImageName.png"]; UIImageView *imgView = [[UIImageView alloc] initWithImage: image]; self.navigationItem.titleView = imgView; 
+3
source

u use this code:

  [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"Image.png"] forBarMetrics:UIBarMetricsDefault]; 
+3
source
 if ([[UINavigationBar class] respondsToSelector:@selector(appearance)]) { [[UINavigationBar appearance] setBackgroundImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:imageName ofType:@"png"]] forBarMetrics:UIBarMetricsDefault]; [[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys: [UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0], UITextAttributeTextColor, [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8], UITextAttributeTextShadowColor, [NSValue valueWithUIOffset:UIOffsetMake(0, 0)], UITextAttributeTextShadowOffset, [UIFont fontWithName:@"HelveticaNeue-Bold" size:18.0], UITextAttributeFont, nil]]; } 

put it in your Appdelegate.m

+2
source

I am perfect because I have such a problem, so you can try your way, ok !!

firstly, you create a navigation controller and then show it in a window

UINavigationController *nav=[[UINavigationController alloc] initWithRootViewController:YourView];

Next step: you create a Uiimageview object with an image property with your image that you want to add a navigation bar and the ptoperty frame is the position you want

UIImageView *imgView=[UIImageView alloc] initWithImage:[UIImage imageNamed:@"YourImagename"]; imgView.Frame=CGrectmake();

final step: you add the imgView object to the navigation bar as a subview

 [nav.navigationBar addSubview:imgView]; 

Done !!!!!!!!!!!

0
source

Source: https://habr.com/ru/post/1482509/


All Articles