Skip to content

Instantly share code, notes, and snippets.

@Nitewriter
Created September 30, 2011 13:56
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save Nitewriter/1253807 to your computer and use it in GitHub Desktop.
Save Nitewriter/1253807 to your computer and use it in GitHub Desktop.
UINavigationController custom navigation bar
- (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;
}
#import <UIKit/UIKit.h>
@interface UINavigationController (MTCustomNavigationBar)
- (id)initWithCustomNavigationBar:(UINavigationBar *)navigationBar;
@end
#import "UINavigationController-MTCustomNavigationBar.h"
#import <objc/runtime.h>
@implementation UINavigationController (MTCustomNavigationBar)
- (id)initWithCustomNavigationBar:(UINavigationBar *)navigationBar
{
self = [self initWithNibName:nil bundle:nil];
if (self)
{
// Init
[self setValue:navigationBar forKey:@"navigationBar"];
}
return self;
}
@end
@wenboqiu
Copy link

thanks for your feedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment