B. Altan Kocaoglu
B. Altan Kocaoglu

Reputation: 393

How can I change navigationBar Background

I try change to background of navigationBar.

Search.h:

#import <UIKit/UIKit.h>

@interface Search : UIViewController

@end

Search.m:

#import "Search.h"

@implementation Search

- (void)viewDidLoad
{

[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

UIImage *image = [UIImage imageNamed:@"navigation_header.png"];

[self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];

}

I can't change navigation background.

Thanks.

Upvotes: 1

Views: 6592

Answers (3)

Mick MacCallum
Mick MacCallum

Reputation: 130183

This is actually simpler to do then you think. In your app delegate...

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"NavBar.png"] forBarMetrics:UIBarMetricsDefault];
    return YES;
}

This will universally change your navigation bar background image.

Note: I believe UINavigationBar's "appearance" property is available in iOS 5 and up.

Upvotes: 4

Prasad G
Prasad G

Reputation: 6718

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    self.viewController = [[[Search alloc] initWithNibName:@"Search" bundle:nil] autorelease];
    navControl = [[UINavigationController alloc] initWithRootViewController:self.viewController];
[self.window addSubview:[navControl view]];
[self.window makeKeyAndVisible];

}

Write this method in AppDelegate.m. I think it will be helpful to you.

Upvotes: 0

Rinju  Jain
Rinju Jain

Reputation: 1694

viewController.h

IBOutlet UINavigationBar *navBar;

viewController.m //for color

- (void)viewDidLoad{  
[super viewDidLoad];
 [navBar setTintColor:[UIColor colorWithRed:0.0/255.0 green:100.0/255.0 blue:20.0/255.0 alpha:1.0]];
}

//for image

 UIImage *image = [UIImage imageNamed:@"navigation_header.png"];
[self.navigationController.navBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];

Upvotes: 2

Related Questions