Reputation: 1639
I want to add background image to uinavigationcontroller. Please help me.
Upvotes: 6
Views: 11333
Reputation: 363
If You want to change navigation bar image from ViewController
Objective C
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"img"] forBarMetrics:UIBarMetricsDefault];
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
Reputation: 363
code on swift 3 and swift 4
UINavigationBar.appearance().setBackgroundImage(UIImage(named:"pattern.png"),
for: .default)
Upvotes: 1
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
Reputation: 27072
Try this
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"yourImage"] forBarMetrics:UIBarMetricsDefault];
Upvotes: 14