Reputation: 41
As I saw when I searched here it was a lot of questions on the same topic, but I really dont know which codes to use and where to put them.
I simply want to change the navigation bar to a custom bar with my own background image.
I did see some codes, but I am really new so I dont know how to do this!
-Simon
Upvotes: 1
Views: 1511
Reputation: 487
//first put this code in AppDelegate.m
in this method:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//code: navigationbar set image and fontcolor:
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"your_navigationimg_bg"] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setTitleVerticalPositionAdjustment:0.0 forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setTitleTextAttributes: @{
UITextAttributeTextShadowColor: [UIColor clearColor],
UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetMake(0.0f, 1.0f)],
UITextAttributeFont: [UIFont fontWithName:@"AppleGothic" size:20.0f]
}];
[self.window makeKeyAndVisible];
return YES;
}
//second: put this code in RootViewController.m
in this method:
- (void)viewDidLoad
{
self.navigationItem.title=@"your title";
[super viewDidLoad];
}
Upvotes: 0
Reputation: 112
Use the appearance property
[[UINavigationBar appearance] setBackgroundImage:yourimage forBarMetrics:UIBarMetricsDefault];
Upvotes: 1