Sunday, June 9, 2013

UINavigationBar barStyle example in Objective C (iOS).


UINavigationBar barStyle

The appearance of the navigation bar.

@property(nonatomic, assign) UIBarStyle barStyle

Discussion of [UINavigationBar barStyle]
See UIBarStyle for possible values. The default value is UIBarStyleDefault.

It is permissible to set the value of this property when the navigation bar is being managed by a navigation controller object.

UINavigationBar barStyle example.
irstViewController *fvc = [[FirstViewController alloc] init];
UINavigationController *navcon = [[UINavigationController alloc] initWithRootViewController:fvc];
[fvc release];

navcon.navigationBar.barStyle = UIBarStyleBlackTranslucent;

[self.window addSubview:navcon.view];
[self.window makeKeyAndVisible];

return YES;

Example of [UINavigationBar barStyle].
The Apple Documentation says to use the following since UIBarStyleBlackTranslucent is deprecated:

navController.navigationBar.barStyle = UIBarStyleBlack;
navController.navigationBar.translucent = YES;
You could try shifting your view back in the correct place or try using the following:

navController.navigationBar.tintColor = [UIColor blackColor];
navController.navigationBar.translucent = YES;

UINavigationBar barStyle example.
In RootViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    [self.navigationController.navigationBar setBarStyle:UIBarStyleDefault];
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"orangeNavigationBar.png"] forBarMetrics:UIBarMetricsDefault];
}
In TranslucentViewController

- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];

    [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setBarStyle:UIBarStyleBlackTranslucent];
}

End of UINavigationBar barStyle example article.