Hasintha Janka
Hasintha Janka

Reputation: 1639

Background Image for UINavigationcontroller

I want to add background image to uinavigationcontroller. Please help me.

Upvotes: 6

Views: 11333

Answers (4)

amisha.beladiya
amisha.beladiya

Reputation: 363

If You want to change navigation bar image from ViewController

  1. Objective C

    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"img"] forBarMetrics:UIBarMetricsDefault];
    
  2. Swift

    self.navigationController?.navigationBar.setBackgroundImage(UIImage(named:"pi2"), for: .default)
    

If You want to change navigation bar image from Appdelegate

 1. Using Objective C

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

 2. Using swift  


func application(_ application: UIApplication, didFinishLaunchingWithOptions 
                              launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool  {
                         UINavigationBar.appearance().setBackgroundImage(UIImage(named:"img"), for:.default)
                         return true
       }

Upvotes: 0

amisha.beladiya
amisha.beladiya

Reputation: 363

code on swift 3 and swift 4

UINavigationBar.appearance().setBackgroundImage(UIImage(named:"pattern.png"),
                                                            for: .default)

Upvotes: 1

Ujwal
Ujwal

Reputation: 154

Use this

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [self.window makeKeyAndVisible];
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"yourImage"] forBarMetrics:UIBarMetricsDefault];
    return YES;
}

Upvotes: 3

Hemang
Hemang

Reputation: 27072

Try this

[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"yourImage"] forBarMetrics:UIBarMetricsDefault];

Upvotes: 14

Related Questions