Xcode4.2 (storyboard, navigation controller) How to set up custom image for UINavigationBar

I am creating an iPhone application using a storyboard. I do not know how to configure a custom image for the UINavigationBar.

Please teach me how to do this. Well, I'm not a programmer, but just a designer.

Thank you so much for giving me some good code.

I put the code in my "MainAppDelegate.m"

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController; SelectClientNavController *controller = (SelectClientNavController *)navigationController.topViewController; [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"yourBackGroundImage.png"] forBarMetrics:UIBarMetricsDefault]; controller.managedObjectContext = self.managedObjectContext; return YES; } 

But I got a few errors, like below !!


For this line:

 SelectClientNavController *controller = (SelectClientNavController *)navigationController.topViewController; 

1. Expected expression

2. Using the undeclared identifier 'SelectClientNavController'

3. Using the implicit identifier 'controller'


For this line:

 controller.managedObjectContext = self.managedObjectContext; 

1. Property "managedObjectContext" was not found on an object of type "MainAppDelegeate" *

2. Using the implicit identifier 'controller'


How can I fix the errors above.


+4
source share
1 answer

I also needed to do this very soon, like this: you cannot do this in a storyboard. The code works best in the application delegation implementation file (AppDelegate.m)., Find the method "- (BOOL) application: (UIApplication *) application didFinishLaunchingWithOptions: (NSDictionary *) launchOptions" and change it as shown below. You will add only one line of code.

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController; // this line is probably already there for you [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"yourBackGroundImage.png"] forBarMetrics:UIBarMetricsDefault]; //this adds the image return YES; } 

Where "yourBackGroundImage.png" is your image. Make sure you add the image to your project.

I believe this will only work for iOS 5.

+5
source

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


All Articles