Showing posts with label UINavigationBar. Show all posts
Showing posts with label UINavigationBar. Show all posts

Sunday, June 9, 2013

UINavigationBar setItems animated example in Objective C (iOS).


UINavigationBar setItems animated

Replaces the navigation items currently managed by the navigation bar with the specified items.

- (void)setItems:(NSArray *)items animated:(BOOL)animated

Parameters of [UINavigationBar setItems animated]
items
The UINavigationItem objects to place in the stack. The front-to-back order of the items in this array represents the new bottom-to-top order of the items in the navigation stack. Thus, the last item added to the array becomes the top item of the navigation stack.
animated
If YES, animate the pushing or popping of the top stack item. If NO, replace the stack items without any animations.

Discussion of [UINavigationBar setItems animated]
You can use this method to update or replace the navigation items in the stack without pushing or popping each item explicitly. In addition, this method lets you update the stack without animating the changes, which might be appropriate at launch time when you want to restore the state of the navigation stack to some previous state.[UINavigationBar setItems animated]

If animations are enabled, this method decides which type of transition to perform based on whether the last item in the items array is already on the current navigation stack. If the item is currently on the stack, but is not the topmost item, this method uses a pop transition; if it is the topmost item, no transition is performed. If the item is not on the stack, this method uses a push transition. Only one transition is performed, but when that transition finishes, the entire contents of the stack are replaced with the new items. For example, if items A, B, and C are on the stack and you set items D, A, and B, this method uses a pop transition and the resulting stack contains the items D, A, and B.

UINavigationBar setItems animated example.
// This code is used for a custom navigation bar

UINavigationItem* newItem = [[UINavigationItem alloc] initWithTitle:@""];
[newItem setTitleView:segmentedControl];

// Assuming you already have a navigation bar called "navigationBar"
[navigationBar setItems:[NSArray arrayWithObject:newItem] animated:NO];

// No memory leaks please...
[newItem release];

Example of [UINavigationBar setItems animated].
[super viewDidLoad];
    _navBar = [[UINavigationBar alloc] init];
    [_navBar setFrame:CGRectMake(0,0,self.view.bounds.size.width,52)];
    [self.view addSubview:_navBar];
    UINavigationItem *navItem = [[UINavigationItem alloc]initWithTitle:@""];
    UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(buttonSettingClicked)];
    [navItem setLeftBarButtonItem:barButton];

    [_navBar setItems:@[navItem]];

UINavigationBar setItems animated example.
- (void)viewDidLoad
{
    [super viewDidLoad];
    UINavigationBar *navigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
    navigationBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    [navigationBar setItems:[NSArray arrayWithObject:[[UINavigationItem alloc]initWithTitle:@"Title"]]];
    navigationBar.topItem.titleView.backgroundColor = [UIColor blueColor];
    [self.view addSubview:navigationBar];
}

End of UINavigationBar setItems animated example article.

UINavigationBar setItems example in Objective C (iOS).


UINavigationBar setItems

Replaces the navigation items currently managed by the navigation bar with the specified items.

- (void)setItems:(NSArray *)items animated:(BOOL)animated

Parameters of [UINavigationBar setItems]
items
The UINavigationItem objects to place in the stack. The front-to-back order of the items in this array represents the new bottom-to-top order of the items in the navigation stack. Thus, the last item added to the array becomes the top item of the navigation stack.
animated
If YES, animate the pushing or popping of the top stack item. If NO, replace the stack items without any animations.

Discussion of [UINavigationBar setItems]
You can use this method to update or replace the navigation items in the stack without pushing or popping each item explicitly. In addition, this method lets you update the stack without animating the changes, which might be appropriate at launch time when you want to restore the state of the navigation stack to some previous state.[UINavigationBar setItems]

If animations are enabled, this method decides which type of transition to perform based on whether the last item in the items array is already on the current navigation stack. If the item is currently on the stack, but is not the topmost item, this method uses a pop transition; if it is the topmost item, no transition is performed. If the item is not on the stack, this method uses a push transition. Only one transition is performed, but when that transition finishes, the entire contents of the stack are replaced with the new items. For example, if items A, B, and C are on the stack and you set items D, A, and B, this method uses a pop transition and the resulting stack contains the items D, A, and B.

UINavigationBar setItems example.
// This code is used for a custom navigation bar

UINavigationItem* newItem = [[UINavigationItem alloc] initWithTitle:@""];
[newItem setTitleView:segmentedControl];

// Assuming you already have a navigation bar called "navigationBar"
[navigationBar setItems:[NSArray arrayWithObject:newItem] animated:NO];

// No memory leaks please...
[newItem release];

Example of [UINavigationBar setItems].
[super viewDidLoad];
    _navBar = [[UINavigationBar alloc] init];
    [_navBar setFrame:CGRectMake(0,0,self.view.bounds.size.width,52)];
    [self.view addSubview:_navBar];
    UINavigationItem *navItem = [[UINavigationItem alloc]initWithTitle:@""];
    UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(buttonSettingClicked)];
    [navItem setLeftBarButtonItem:barButton];

    [_navBar setItems:@[navItem]];

UINavigationBar setItems example.
- (void)viewDidLoad
{
    [super viewDidLoad];
    UINavigationBar *navigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
    navigationBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    [navigationBar setItems:[NSArray arrayWithObject:[[UINavigationItem alloc]initWithTitle:@"Title"]]];
    navigationBar.topItem.titleView.backgroundColor = [UIColor blueColor];
    [self.view addSubview:navigationBar];
}

End of UINavigationBar setItems example article.

UINavigationBar setBackgroundImage forBarMetrics example in Objective C (iOS).


UINavigationBar setBackgroundImage forBarMetrics

Sets the background image for given bar metrics.

- (void)setBackgroundImage:(UIImage *)backgroundImage forBarMetrics:(UIBarMetrics)barMetrics

Parameters of [UINavigationBar setBackgroundImage forBarMetrics]
backgroundImage
The background image to use for barMetrics.
barMetrics
A bar metrics constant.
UINavigationBar setBackgroundImage forBarMetrics example.
To apply image to all your navigation bars, use the appearance proxy:

[[UINavigationBar appearance] setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
For an individual bar:

// Assuming "self" is a view controller pushed on to a UINavigationController stack
[self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];

Example of [UINavigationBar setBackgroundImage forBarMetrics].
if( [self.navigationController.navigationBar respondsToSelector: @selector(setBackgroundImage:forBarMetrics:)]) {
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navbar.png"]
                                                  forBarMetrics:UIBarMetricsDefault];

}else {
    UIImageView* imgBG = [[UIImageView alloc]init];
    imgBG.image = [UIImage imageNamed:@"navbar.png"];
    imgBG.frame = CGRectMake(-10,0, 330, 44);
    [parentViewLeft addSubview:imgBG];

}
UIBarButtonItem *customBarButtomLeft = [[UIBarButtonItem alloc] initWithCustomView:parentViewLeft];
self.navigationItem.leftBarButtonItem = customBarButtomLeft;

UINavigationBar setBackgroundImage forBarMetrics example.
If you use iOS4, you can override - (void)drawRect

@implementation UINavigationBar (UINavigationBarCategory)

- (void)drawRect:(CGRect)rect
{
    UIImage *navBg = [UIImage imageNamed:@"navBar.png"];
    [navBg drawInRect:rect];
}
@end
iOS 5,

if ([[UIDevice currentDevice].systemVersion floatValue] >= 5.0) {
    if ([self.navigationController.navigationBar respondsToSelector:@selector( setBackgroundImage:forBarMetrics:)]){

        UIImage *navBarImg = [UIImage imageNamed:@"navBar.png"];

        [self.navigationController.navigationBar setBackgroundImage:navBarImg forBarMetrics:UIBarMetricsDefault];

    }
}

End of UINavigationBar setBackgroundImage forBarMetrics example article.

UINavigationBar setBackgroundImage example in Objective C (iOS).


UINavigationBar setBackgroundImage

Sets the background image for given bar metrics.

- (void)setBackgroundImage:(UIImage *)backgroundImage forBarMetrics:(UIBarMetrics)barMetrics

Parameters of [UINavigationBar setBackgroundImage]
backgroundImage
The background image to use for barMetrics.
barMetrics
A bar metrics constant.
UINavigationBar setBackgroundImage example.
To apply image to all your navigation bars, use the appearance proxy:

[[UINavigationBar appearance] setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
For an individual bar:

// Assuming "self" is a view controller pushed on to a UINavigationController stack
[self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];

Example of [UINavigationBar setBackgroundImage].
if( [self.navigationController.navigationBar respondsToSelector: @selector(setBackgroundImage:forBarMetrics:)]) {
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navbar.png"]
                                                  forBarMetrics:UIBarMetricsDefault];

}else {
    UIImageView* imgBG = [[UIImageView alloc]init];
    imgBG.image = [UIImage imageNamed:@"navbar.png"];
    imgBG.frame = CGRectMake(-10,0, 330, 44);
    [parentViewLeft addSubview:imgBG];

}
UIBarButtonItem *customBarButtomLeft = [[UIBarButtonItem alloc] initWithCustomView:parentViewLeft];
self.navigationItem.leftBarButtonItem = customBarButtomLeft;

UINavigationBar setBackgroundImage example.
If you use iOS4, you can override - (void)drawRect

@implementation UINavigationBar (UINavigationBarCategory)

- (void)drawRect:(CGRect)rect
{
    UIImage *navBg = [UIImage imageNamed:@"navBar.png"];
    [navBg drawInRect:rect];
}
@end
iOS 5,

if ([[UIDevice currentDevice].systemVersion floatValue] >= 5.0) {
    if ([self.navigationController.navigationBar respondsToSelector:@selector( setBackgroundImage:forBarMetrics:)]){

        UIImage *navBarImg = [UIImage imageNamed:@"navBar.png"];

        [self.navigationController.navigationBar setBackgroundImage:navBarImg forBarMetrics:UIBarMetricsDefault];

    }
}

End of UINavigationBar setBackgroundImage example article.

UINavigationBar pushNavigationItem example in Objective C (iOS).


UINavigationBar pushNavigationItem

Pushes the given navigation item onto the receiver’s stack and updates the navigation bar.

- (void)pushNavigationItem:(UINavigationItem *)item animated:(BOOL)animated

Parameters
item
The navigation item to push on the stack.
animated
YES if the navigation bar should be animated; otherwise, NO.

Discussion of [UINavigationBar pushNavigationItem]
Pushing a navigation item displays the item’s title in the center on the navigation bar. The previous top navigation item (if it exists) is displayed as a back button on the left side of the navigation bar. If the new top item has a left custom view, it is displayed instead of the back button.

UINavigationBar pushNavigationItem example.
On your navigationbar reference you could invoke the two methods:

- (void)pushNavigationItem:(UINavigationItem *)item animated:(BOOL)animated
- (UINavigationItem *)popNavigationItemAnimated:(BOOL)animated
In your custom view controller class write something like this:

self.navigationItem.leftBarButtonItem = yourButton;
self.navigationItem.rightBarButtonItem = yourSecondButton;
So you could write something like this:

[myNavBarReference pushNavigationItem:self.navigationItem animated:NO];

Example of [UINavigationBar pushNavigationItem].
Try using the navigation item's title property for this:

UINavigationItem *item = [[[UINavigationItem alloc] initWithTitle:@"Login"] autorelease];
[yourNavigationBar pushNavigationItem:item animated:NO];

UINavigationBar pushNavigationItem example.
UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc] 
initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self 
action:@selector(toggleHelpGame)];
                        UINavigationItem *navigationItem = [[UINavigationItem alloc] 
initWithTitle:@"Help"];
                        navigationItem.rightBarButtonItem = buttonItem;
                        [navigationItem setLeftBarButtonItem:nil];
                        [self.sideNavigationBarCtrl pushNavigationItem:navigationItem 
animated:NO];
                        [navigationItem release];
                        [buttonItem release];

End of UINavigationBar pushNavigationItem example article.

UINavigationBar popNavigationItemAnimated example in Objective C (iOS).


UINavigationBar popNavigationItemAnimated

Pops the top item from the receiver’s stack and updates the navigation bar.

- (UINavigationItem *)popNavigationItemAnimated:(BOOL)animated

Parameters
animated
YES if the navigation bar should be animated; otherwise, NO.

Return Value
The top item that was popped.

Discussion of [UINavigationBar popNavigationItemAnimated]
Popping a navigation item removes the top item from the stack and replaces it with the back item. The back item’s title is centered on the navigation bar and its other properties are displayed.

UINavigationBar popNavigationItemAnimated example.
#import "AppDelegate.h"

@implementation UINavigationBar (custom)
- (UINavigationItem *)popNavigationItemAnimated:(BOOL)animated;
{

    AppDelegate *delegate = [[UIApplication sharedApplication] delegate];

    [delegate.navController popViewControllerAnimated:NO];

    return TRUE;
}

@end

Example of [UINavigationBar popNavigationItemAnimated].
- (BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPopItem:(UINavigationItem *)item {

if ([[navigationBar items] indexOfObject:item] == 1) {
    [expandedStack restack];   
}

if (!progPop) {
    progPop = YES;
    [navBar popNavigationItemAnimated:NO];
    return NO;
}

else {
    progPop = NO;
    return YES;
}
}

UINavigationBar popNavigationItemAnimated example.
To prevent the navigation bar from being animated it is not sufficient to override (UIViewController *)popViewControllerAnimated:(BOOL)animated. It is also necessary to create a custom navigation bar and override (UINavigationItem *)popNavigationItemAnimated:(BOOL)animated:

- (UINavigationItem *)popNavigationItemAnimated:(BOOL)animated {
    return [super popNavigationItemAnimated:NO];
}

End of UINavigationBar popNavigationItemAnimated example article.

UINavigationBar setTranslucent example in Objective C (iOS).


UINavigationBar setTranslucent

A Boolean value indicating whether the navigation bar is only partially opaque.

@property(nonatomic, assign, getter=isTranslucent) BOOL translucent

Discussion of [UINavigationBar setTranslucent]
Always set to YES if the barStyle property contains the value UIBarStyleBlackTranslucent. When YES, the navigation bar is drawn with partial opacity, regardless of the bar style. The amount of opacity is fixed and cannot be changed.

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

UINavigationBar setTranslucent example.
the translucent property of UINavigationBar. Try:

[[self.navigationController navigationBar] setTranslucent:YES];

Example of [UINavigationBar setTranslucent].
Once you know it, it's fairly simple:

self.navigationController.navigationBar.tintColor = [UIColor blueColor];
self.navigationController.navigationBar.alpha = 0.7f;
self.navigationController.navigationBar.translucent = YES;
The translucent property seems only to determine wether the main view should be visible under the navigation bar, and resizes the view appropiately.

UINavigationBar setTranslucent example.
At least in iOS 6 on an iPhone 4S, you can make a colored translucent navigation bar like this:

self.navigationController.navigationBar.tintColor = [UIColor blueColor];
self.navigationController.navigationBar.translucent = YES;
The alpha setting doesn't seem to be necessary anymore. This also leaves my title bright white and my buttons opaque.

End of UINavigationBar setTranslucent example article.

UINavigationBar translucent example in Objective C (iOS).


UINavigationBar translucent

A Boolean value indicating whether the navigation bar is only partially opaque.

@property(nonatomic, assign, getter=isTranslucent) BOOL translucent

Discussion of [UINavigationBar translucent]
Always set to YES if the barStyle property contains the value UIBarStyleBlackTranslucent. When YES, the navigation bar is drawn with partial opacity, regardless of the bar style. The amount of opacity is fixed and cannot be changed.

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

UINavigationBar translucent example.
the translucent property of UINavigationBar. Try:

[[self.navigationController navigationBar] setTranslucent:YES];

Example of [UINavigationBar translucent].
Once you know it, it's fairly simple:

self.navigationController.navigationBar.tintColor = [UIColor blueColor];
self.navigationController.navigationBar.alpha = 0.7f;
self.navigationController.navigationBar.translucent = YES;
The translucent property seems only to determine wether the main view should be visible under the navigation bar, and resizes the view appropiately.

UINavigationBar translucent example.
At least in iOS 6 on an iPhone 4S, you can make a colored translucent navigation bar like this:

self.navigationController.navigationBar.tintColor = [UIColor blueColor];
self.navigationController.navigationBar.translucent = YES;
The alpha setting doesn't seem to be necessary anymore. This also leaves my title bright white and my buttons opaque.

End of UINavigationBar translucent example article.

UINavigationBar topItem example in Objective C (iOS).


UINavigationBar topItem

The navigation item at the top of the navigation bar’s stack. (read-only)

@property(nonatomic, readonly, retain) UINavigationItem *topItem

UINavigationBar topItem example.
OK, I assume you have a reference to your UINavigationBar? Then I guess you'd add a single UINavigationItem to it:

UINavigationItem *item = [[UINavigationItem alloc] initWithTitle:@"A Title"];
theNavigationBar.items = [NSArray arrayWithObject:item];
[item release]; // or keep this as an instance variable
and then set that item's left and right buttons:

theNavigationBar.topItem.leftBarButtonItem = ...;
theNavigationBar.topItem.rightBarButtonItem = ...;

Example of [UINavigationBar topItem].
I've set the title programatically using code something like this:

navBar.topItem.title = @"title";
where navBar is declared as an IBOutlet UINavigationBar linked to the navigation bar in interface builder. This worked in my app; however, I was not using a tab bar.

If navBar.topItem is the tab bar item, I don't see a way for you to change the title that appears on the navigation bar without also changing the title on the tab bar item, since the navBar's topItem and the tab bar item is the same object.

UINavigationBar topItem example.
UINavigationItem* item = [[UINavigationItem alloc] initWithTitle:@"title text"];
...
[bar pushNavigationItem:item animated:YES];
[item release];
or

bar.topItem.title = @"title text";

End of UINavigationBar topItem example article.

UINavigationBar setTitleTextAttributes example in Objective C (iOS).


UINavigationBar setTitleTextAttributes

Display attributes for the bar’s title text.

@property(nonatomic, copy) NSDictionary *titleTextAttributes

Discussion of [UINavigationBar setTitleTextAttributes]
You can specify the font, text color, text shadow color, and text shadow offset for the title in the text attributes dictionary, using the text attribute keys described in NSString UIKit Additions Reference.

UINavigationBar setTitleTextAttributes example.
In iOS 5 you can change the navigationBar title color in this manner:

navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor yellowColor] forKey:UITextAttributeTextColor];

Example of [UINavigationBar setTitleTextAttributes].
I do believe proper way to set the colour of UINavigationBar is:

NSDictionary *attributes=[NSDictionary dictionaryWithObjectsAndKeys:[UIColor redColor],UITextAttributeTextColor, nil];
self.titleTextAttributes = attributes;

UINavigationBar setTitleTextAttributes example.
// Customize the title text for *all* UINavigationBars
[[UINavigationBar appearance] setTitleTextAttributes:
    [NSDictionary dictionaryWithObjectsAndKeys:
        [UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0],
        UITextAttributeTextColor,
        [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8],
        UITextAttributeTextShadowColor,
        [NSValue valueWithUIOffset:UIOffsetMake(0, -1)],
        UITextAttributeTextShadowOffset,
        [UIFont fontWithName:@"Arial-Bold" size:0.0],
        UITextAttributeFont,
        nil]];
Or if you prefer with the object literal style:

[[UINavigationBar appearance] setTitleTextAttributes:@{
    UITextAttributeTextColor: [UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0],
    UITextAttributeTextShadowColor: [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8],
    UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetMake(0, -1)],
    UITextAttributeFont: [UIFont fontWithName:@"Arial-Bold" size:0.0],
}];

End of UINavigationBar setTitleTextAttributes example article.

UINavigationBar titleTextAttributes example in Objective C (iOS).


UINavigationBar titleTextAttributes

Display attributes for the bar’s title text.

@property(nonatomic, copy) NSDictionary *titleTextAttributes

Discussion of [UINavigationBar titleTextAttributes]
You can specify the font, text color, text shadow color, and text shadow offset for the title in the text attributes dictionary, using the text attribute keys described in NSString UIKit Additions Reference.

UINavigationBar titleTextAttributes example.
In iOS 5 you can change the navigationBar title color in this manner:

navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor yellowColor] forKey:UITextAttributeTextColor];

Example of [UINavigationBar titleTextAttributes].
I do believe proper way to set the colour of UINavigationBar is:

NSDictionary *attributes=[NSDictionary dictionaryWithObjectsAndKeys:[UIColor redColor],UITextAttributeTextColor, nil];
self.titleTextAttributes = attributes;

UINavigationBar titleTextAttributes example.
// Customize the title text for *all* UINavigationBars
[[UINavigationBar appearance] setTitleTextAttributes:
    [NSDictionary dictionaryWithObjectsAndKeys:
        [UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0],
        UITextAttributeTextColor,
        [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8],
        UITextAttributeTextShadowColor,
        [NSValue valueWithUIOffset:UIOffsetMake(0, -1)],
        UITextAttributeTextShadowOffset,
        [UIFont fontWithName:@"Arial-Bold" size:0.0],
        UITextAttributeFont,
        nil]];
Or if you prefer with the object literal style:

[[UINavigationBar appearance] setTitleTextAttributes:@{
    UITextAttributeTextColor: [UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0],
    UITextAttributeTextShadowColor: [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8],
    UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetMake(0, -1)],
    UITextAttributeFont: [UIFont fontWithName:@"Arial-Bold" size:0.0],
}];

End of UINavigationBar titleTextAttributes example article.

UINavigationBar tintColor example in Objective C (iOS).


UINavigationBar tintColor

The color used to tint the bar.

@property(nonatomic, retain) UIColor *tintColor

Discussion of [UINavigationBar tintColor]
The default value is nil.

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

UINavigationBar tintColor example.
Set the barStyle to UIBarStyleBlackTranslucent Set the tintColor like this:

navigationBar.tintColor = [UIColor colorWithRed:.7 green:.5 blue:.2 alpha:1];
This will set the appropriate gradient. Use whatever combination you need.


Example of [UINavigationBar tintColor].
That is one way of doing it. It would probably just be easier in you ViewController where ever you need to change it add the line:

self.navigationController.navigationBar.tintColor = [UIColor redColor];

UINavigationBar tintColor example.
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    tintBarColor = [UIColor  
                colorWithRed:50.0/255  
                green:134.0/255  
                blue:187.0/255  
                alpha:1];
    self.navigationController.navigationBar.tintColor = tintBarColor;
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    [tintBarColor release];
    // Relinquish ownership of anything that can be recreated in viewDidLoad or on     demand.
    // For example: self.myOutlet = nil;
}

End of UINavigationBar tintColor example article.

UINavigationBar setShadowImage example in Objective C (iOS).


UINavigationBar setShadowImage

The shadow image to be used for the navigation bar.

@property(nonatomic,retain) UIImage *shadowImage

Discussion of [UINavigationBar setShadowImage]
The default value is nil, which corresponds to the default shadow image. When non-nil, this property represents a custom shadow image to show instead of the default. For a custom shadow image to be shown, a custom background image must also be set with the setBackgroundImage:forBarMetrics: method. If the default background image is used, then the default shadow image will be used regardless of the value of this property.

UINavigationBar setShadowImage example.
if ([self.navigationController.navigationBar
respondsToSelector:@selector(shadowImage)]) {
self.navigationController.navigationBar.shadowImage = [[[UIImage alloc] init] autorelease];
}

Example of [UINavigationBar setShadowImage].
You have to do the work on a NavigationBar instance...

if ([navigationBarInstance respondsToSelector:@selector(setShadowImage:)]){
    [navigationBarInstance setShadowImage:[[UIImage alloc] init]];
}

UINavigationBar setShadowImage example.
iOS6 has added a drop shadow to the Navigation Bar. So the masking code that I was using with iOS5 still works fine - I just need to add

if ([self.navigationController.navigationBar respondsToSelector:@selector(shadowImage)])
{
[self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
}
to get rid of the drop shadow.

End of UINavigationBar setShadowImage example article.

UINavigationBar shadowImage example in Objective C (iOS).


UINavigationBar shadowImage

The shadow image to be used for the navigation bar.

@property(nonatomic,retain) UIImage *shadowImage

Discussion of [UINavigationBar shadowImage]
The default value is nil, which corresponds to the default shadow image. When non-nil, this property represents a custom shadow image to show instead of the default. For a custom shadow image to be shown, a custom background image must also be set with the setBackgroundImage:forBarMetrics: method. If the default background image is used, then the default shadow image will be used regardless of the value of this property.

UINavigationBar shadowImage example.
if ([self.navigationController.navigationBar
respondsToSelector:@selector(shadowImage)]) {
self.navigationController.navigationBar.shadowImage = [[[UIImage alloc] init] autorelease];
}

Example of [UINavigationBar shadowImage].
You have to do the work on a NavigationBar instance...

if ([navigationBarInstance respondsToSelector:@selector(setShadowImage:)]){
    [navigationBarInstance setShadowImage:[[UIImage alloc] init]];
}

UINavigationBar shadowImage example.
iOS6 has added a drop shadow to the Navigation Bar. So the masking code that I was using with iOS5 still works fine - I just need to add

if ([self.navigationController.navigationBar respondsToSelector:@selector(shadowImage)])
{
[self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
}
to get rid of the drop shadow.

End of UINavigationBar shadowImage example article.

UINavigationBar setBarStyle example in Objective C (iOS).


UINavigationBar setBarStyle

The appearance of the navigation bar.

@property(nonatomic, assign) UIBarStyle barStyle

Discussion of [UINavigationBar setBarStyle]
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 setBarStyle 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 setBarStyle].
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 setBarStyle 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 setBarStyle example article.

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.