I want to add an image in the navigation bar. It should be throughout my app. It should be added to all navigation controllers.
Any help will be appreciated.
I want to add an image in the navigation bar. It should be throughout my app. It should be added to all navigation controllers.
Any help will be appreciated.
Try this ,
UINavigationBar *navBar = self.navigationController.navigationBar;
UIImage *image = [UIImage imageNamed:@"image.png"];
[navBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
you can add image with bellow code..
UIImage *image = [UIImage imageNamed: @"yourImageName.png"];
UIImageView *imgView = [[UIImageView alloc] initWithImage: image];
self.navigationItem.titleView = imgView;
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 this in your Appdelegate.m
u use this code:
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"Image.png"] forBarMetrics:UIBarMetricsDefault];
i am an ideal , because i have got issue like this ,so you can try my way,ok!!
the first,you create an navigationcontroller and then show it on window
UINavigationController *nav=[[UINavigationController alloc] initWithRootViewController:YourView];
next step : you create an object Uiimageview with image property with your image which you want to add navigationbar and frame ptoperty is posittion which you want
UIImageView *imgView=[UIImageView alloc] initWithImage:[UIImage imageNamed:@"YourImagename"];
imgView.Frame=CGrectmake();
last step: you add object imgView in navigationbar as subview
[nav.navigationBar addSubview:imgView];
Done!!!!!!!!!!