Created
September 30, 2011 13:56
-
-
Save Nitewriter/1253807 to your computer and use it in GitHub Desktop.
UINavigationController custom navigation bar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions | |
{ | |
// Override point for customization after application launch. | |
// Create a new window and assign directly to provided iVar | |
_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; | |
// Implementation of new init method | |
MyCustomNavigationBar *navigationBar = [[MyCustomNavigationBar alloc] initWithFrame:CGRectZero]; | |
UINavigationController *navigationController = [[UINavigationController alloc] initWithCustomNavigationBar:navigationBar]; | |
[navigationBar release]; | |
[self.window setRootViewController:navigationController]; | |
[navigationController release]; | |
[self.window makeKeyAndVisible]; | |
return YES; | |
} |
This method is not ARC compatible. If you are using ARC you can simply replace the navigation bar using:
[navigationController setValue:navigationBar forKey:@"navigationBar"].
Hi Nitewriter:
I test your code on ios5.1, the custom navigation bar appears, but the back button on the bar doesn't work, it doesn't call popViewControllerAnimated method when tap back button, however the back button will disappear...it is weird.
best regards
iOS 5.x introduced changes to the UINavigationBar that cause issues when using this method of replacement. You should use the setValue:forKey: replacement I mentioned to ihmunro.
thanks for your feedback
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Does not work