Showing posts with label UINavigationItem. Show all posts
Showing posts with label UINavigationItem. Show all posts

Sunday, June 9, 2013

UINavigationItem setRightBarButtonItems animated example in Objective C (iOS).


UINavigationItem setRightBarButtonItems animated

Sets the right bar button items, optionally animating the transition to the new items.

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

Parameters of [UINavigationItem setRightBarButtonItems animated]
items
An array of custom bar button items to display on the right side of the navigation bar.
animated
Specify YES to animate the transition to the custom bar items when this item is the top item. Specify NO to set the items immediately without animating the change.

Discussion of [UINavigationItem setRightBarButtonItems animated]
If two navigation items have the same custom left or right bar button items, those bar button items remain stationary during the transition when the navigation item is pushed or popped.

UINavigationItem setRightBarButtonItems animated example.
With iOS 5+ it's as easy as:

UIBarButtonItem *btnShare = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(share)];
UIBarButtonItem *btnRefresh = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(loadBeeconSite)];
[self.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects:btnShare, btnRefresh, nil] animated:NO];

Example of [UINavigationItem setRightBarButtonItems animated].
With iOS 5+
QLPreviewController *previewer = [[[QLPreviewController alloc] init] autorelease];
[previewer setDataSource:self];

UIBarButtonItem *saveButton = [[UIBarButtonItem alloc]initWithTitle:@"Salva Documento" style:UIBarButtonItemStyleBordered target:self action:@selector(saveFileToDocuments)];
NSArray *buttons = [NSArray arrayWithObjects:[[previewer navigationItem]rightBarButtonItem],saveButton, nil];
[[previewer navigationItem] setRightBarButtonItems:buttons animated:NO];

UINavigationItem setRightBarButtonItems animated example.
UINavigationBar *navBarView = [[UINavigationBar alloc] initWithFrame: CGRectMake(0.0f, 0.0f, 320.0f, 42.0f)];
    navBarView.tintColor= [UIColor colorWithRed:90.0/255.0f green:53.0/255.0f blue:45.0/255.0f alpha:1.0];

    UIBarButtonItem *left=[[UIBarButtonItem alloc]initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:self action:@selector(backView)];
    UIBarButtonItem *right=[[UIBarButtonItem alloc]initWithTitle:@"Save" style:UIBarButtonItemStylePlain target:self action:@selector(SaveImage)];
    UIBarButtonItem *Add=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(AddComment:)];

    UINavigationItem *navigationItem = [[UINavigationItem alloc] init];
    navigationItem.leftBarButtonItem = left;
    NSMutableArray *buttonArray=[[NSMutableArray alloc]initWithCapacity:2];
    [buttonArray addObject:right];
    [buttonArray addObject:Add];
    [navigationItem setRightBarButtonItems:buttonArray animated:NO];
    [navBarView pushNavigationItem:navigationItem animated:NO];
[self.view addSubView:navBarView];

End of UINavigationItem setRightBarButtonItems animated example article.

UINavigationItem setRightBarButtonItems example in Objective C (iOS).


UINavigationItem setRightBarButtonItems

Sets the right bar button items, optionally animating the transition to the new items.

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

Parameters of [UINavigationItem setRightBarButtonItems]
items
An array of custom bar button items to display on the right side of the navigation bar.
animated
Specify YES to animate the transition to the custom bar items when this item is the top item. Specify NO to set the items immediately without animating the change.

Discussion of [UINavigationItem setRightBarButtonItems]
If two navigation items have the same custom left or right bar button items, those bar button items remain stationary during the transition when the navigation item is pushed or popped.

UINavigationItem setRightBarButtonItems example.
With iOS 5+ it's as easy as:

UIBarButtonItem *btnShare = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(share)];
UIBarButtonItem *btnRefresh = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(loadBeeconSite)];
[self.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects:btnShare, btnRefresh, nil] animated:NO];

Example of [UINavigationItem setRightBarButtonItems].
With iOS 5+
QLPreviewController *previewer = [[[QLPreviewController alloc] init] autorelease];
[previewer setDataSource:self];

UIBarButtonItem *saveButton = [[UIBarButtonItem alloc]initWithTitle:@"Salva Documento" style:UIBarButtonItemStyleBordered target:self action:@selector(saveFileToDocuments)];
NSArray *buttons = [NSArray arrayWithObjects:[[previewer navigationItem]rightBarButtonItem],saveButton, nil];
[[previewer navigationItem] setRightBarButtonItems:buttons animated:NO];

UINavigationItem setRightBarButtonItems example.
UINavigationBar *navBarView = [[UINavigationBar alloc] initWithFrame: CGRectMake(0.0f, 0.0f, 320.0f, 42.0f)];
    navBarView.tintColor= [UIColor colorWithRed:90.0/255.0f green:53.0/255.0f blue:45.0/255.0f alpha:1.0];

    UIBarButtonItem *left=[[UIBarButtonItem alloc]initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:self action:@selector(backView)];
    UIBarButtonItem *right=[[UIBarButtonItem alloc]initWithTitle:@"Save" style:UIBarButtonItemStylePlain target:self action:@selector(SaveImage)];
    UIBarButtonItem *Add=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(AddComment:)];

    UINavigationItem *navigationItem = [[UINavigationItem alloc] init];
    navigationItem.leftBarButtonItem = left;
    NSMutableArray *buttonArray=[[NSMutableArray alloc]initWithCapacity:2];
    [buttonArray addObject:right];
    [buttonArray addObject:Add];
    [navigationItem setRightBarButtonItems:buttonArray animated:NO];
    [navBarView pushNavigationItem:navigationItem animated:NO];
[self.view addSubView:navBarView];

End of UINavigationItem setRightBarButtonItems example article.

UINavigationItem setRightBarButtonItem animated example in Objective C (iOS).


UINavigationItem setRightBarButtonItem animated

Sets the custom bar button item, optionally animating the transition to the view.

- (void)setRightBarButtonItem:(UIBarButtonItem *)item animated:(BOOL)animated

Parameters of [UINavigationItem setRightBarButtonItem animated]
item
A custom bar item to display on the right of the navigation bar.
animated
Specify YES to animate the transition to the custom bar item when this item is the top item. Specify NO to set the item immediately without animating the change.

Discussion of [UINavigationItem setRightBarButtonItem animated]
If two navigation items have the same custom left or right bar button items, those bar button items remain stationary during the transition when the navigation item is pushed or popped.

UINavigationItem setRightBarButtonItem animated example.
UINavigationItem *backNavItem = [[UINavigationItem alloc] initWithTitle:@"TESTTEST"];
[backNavItem setRightBarButtonItem:backButton animated:YES];

Example of [UINavigationItem setRightBarButtonItem animated].
UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(theEditMethod:)];    
[viewController.navigationItem setLeftBarButtonItem:leftBarButton animated:NO];
[leftBarButton release];

UIBarButtonItem *rightBarButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(theAddMethod:)];     
[viewController.navigationItem setRightBarButtonItem:rightBarButton animated:NO];
[rightBarButton release];

End of UINavigationItem setRightBarButtonItem animated example article.

UINavigationItem setRightBarButtonItem example in Objective C (iOS).


UINavigationItem setRightBarButtonItem

Sets the custom bar button item, optionally animating the transition to the view.

- (void)setRightBarButtonItem:(UIBarButtonItem *)item animated:(BOOL)animated

Parameters of [UINavigationItem setRightBarButtonItem]
item
A custom bar item to display on the right of the navigation bar.
animated
Specify YES to animate the transition to the custom bar item when this item is the top item. Specify NO to set the item immediately without animating the change.

Discussion of [UINavigationItem setRightBarButtonItem]
If two navigation items have the same custom left or right bar button items, those bar button items remain stationary during the transition when the navigation item is pushed or popped.

UINavigationItem setRightBarButtonItem example.
UINavigationItem *backNavItem = [[UINavigationItem alloc] initWithTitle:@"TESTTEST"];
[backNavItem setRightBarButtonItem:backButton animated:YES];

Example of [UINavigationItem setRightBarButtonItem].
UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(theEditMethod:)];    
[viewController.navigationItem setLeftBarButtonItem:leftBarButton animated:NO];
[leftBarButton release];

UIBarButtonItem *rightBarButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(theAddMethod:)];     
[viewController.navigationItem setRightBarButtonItem:rightBarButton animated:NO];
[rightBarButton release];

End of UINavigationItem setRightBarButtonItem example article.

UINavigationItem setLeftBarButtonItems animated example in Objective C (iOS).


UINavigationItem setLeftBarButtonItems animated

Sets the left bar button items, optionally animating the transition to the new items.

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

Parameters of [UINavigationItem setLeftBarButtonItems animated]
items
An array of custom bar button items to display on the left side of the navigation bar.
animated
Specify YES to animate the transition to the custom bar items when this item is the top item. Specify NO to set the items immediately without animating the change.

Discussion of [UINavigationItem setLeftBarButtonItems animated]
If two navigation items have the same custom left or right bar button items, those bar button items remain stationary during the transition when the navigation item is pushed or popped.

UINavigationItem setLeftBarButtonItems animated example.
Assuming iOS 5 onwards add your custom buttons:

[self.navigationItem setLeftBarButtonItems:[NSArray arrayWithObjects: customBarItem, customBarItemSetting, nil] animated:NO];

End of UINavigationItem setLeftBarButtonItems animated example article.

UINavigationItem setLeftBarButtonItems example in Objective C (iOS).


UINavigationItem setLeftBarButtonItems

Sets the left bar button items, optionally animating the transition to the new items.

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

Parameters of [UINavigationItem setLeftBarButtonItems]
items
An array of custom bar button items to display on the left side of the navigation bar.
animated
Specify YES to animate the transition to the custom bar items when this item is the top item. Specify NO to set the items immediately without animating the change.

Discussion of [UINavigationItem setLeftBarButtonItems]
If two navigation items have the same custom left or right bar button items, those bar button items remain stationary during the transition when the navigation item is pushed or popped.

UINavigationItem setLeftBarButtonItems example.
Assuming iOS 5 onwards add your custom buttons:

[self.navigationItem setLeftBarButtonItems:[NSArray arrayWithObjects: customBarItem, customBarItemSetting, nil] animated:NO];

End of UINavigationItem setLeftBarButtonItems example article.

UINavigationItem setLeftBarButtonItem example in Objective C (iOS).


UINavigationItem setLeftBarButtonItem

Sets the custom bar button item, optionally animating the transition to the new item.

- (void)setLeftBarButtonItem:(UIBarButtonItem *)item animated:(BOOL)animated

Parameters[UINavigationItem setLeftBarButtonItem]
item
A custom bar item to display on the left side of the navigation bar.
animated
Specify YES to animate the transition to the custom bar item when this item is the top item. Specify NO to set the item immediately without animating the change.

Discussion of [UINavigationItem setLeftBarButtonItem]
If two navigation items have the same custom left or right bar button items, those bar button items remain stationary during the transition when the navigation item is pushed or popped.

UINavigationItem setLeftBarButtonItem example.
[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]];

Example of [UINavigationItem setLeftBarButtonItem].
UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(theEditMethod:)];     
[viewController.navigationItem setLeftBarButtonItem:leftBarButton animated:NO];
[leftBarButton release];

UIBarButtonItem *rightBarButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(theAddMethod:)];      
[viewController.navigationItem setRightBarButtonItem:rightBarButton animated:NO];
[rightBarButton release];

UINavigationItem setLeftBarButtonItem example.
Assuming iOS 5 onwards add your custom buttons:

[self.navigationItem setLeftBarButtonItems:[NSArray arrayWithObjects: customBarItem, customBarItemSetting, nil] animated:NO];

End of UINavigationItem setLeftBarButtonItem example article.

UINavigationItem setHidesBackButton example in Objective C (iOS).


UINavigationItem setHidesBackButton

Sets whether the back button is hidden, optionally animating the transition.

- (void)setHidesBackButton:(BOOL)hidesBackButton animated:(BOOL)animated

Parameters of [UINavigationItem setHidesBackButton]
hidesBackButton
Specify YES if the back button should be hidden when this navigation item is the top item. Specify NO if the back button should be visible, assuming it has not been replaced by a custom item.
animated
YES to animate the transition; otherwise, NO.

UINavigationItem setHidesBackButton example.
in a controller use this:

[self.navigationItem setHidesBackButton:YES animated:YES];
And to restore it:

[self.navigationItem setHidesBackButton:NO animated:YES];

Example of [UINavigationItem setHidesBackButton].
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
    if (editing) {
        // Disable the back button
        [self.navigationItem setHidesBackButton:YES animated:YES];
    }
    else {
        // Enable the back button
        [self.navigationItem setHidesBackButton:NO animated:YES];
    }

    [super setEditing:editing animated:animated];
}

UINavigationItem setHidesBackButton example.
-(void)viewDidAppear:(BOOL)animated
{
    if ([tempAry count]==0)
    {
        [self.navigationItem setHidesBackButton:YES animated:YES];
    }
    else
    {
        [self.navigationItem setHidesBackButton:NO animated:YES];
    }
    [super viewDidAppear:animated];
} 

End of UINavigationItem setHidesBackButton example article.

UINavigationItem initWithTitle example in Objective C (iOS).


UINavigationItem initWithTitle

Returns a navigation item initialized with the specified title.

- (id)initWithTitle:(NSString *)title

Parameters
title
The string to set as the navigation item’s title displayed in the center of the navigation bar.

Return Value
A new UINavigationItem object initialized with the specified title.

Discussion of [UINavigationItem initWithTitle]
This is the designated initializer for this class.

UINavigationItem initWithTitle example.
- (void)loadView
{
    self.view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
    self.view.backgroundColor = [UIColor redColor];
    self.title = @"MainVC";

    UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:@"SecondLevel" style:UIBarButtonItemStyleBordered target:self action:@selector(secondLevelSelected:)];
    self.navigationItem.rightBarButtonItem = rightButton;
}

- (void) secondLevelSelected:(id)sender
{
    SecondVC *secondVC = [[SecondVC alloc]  init];
    [self.navigationController pushViewController:secondVC animated:YES];
}

Example of [UINavigationItem initWithTitle].
- (void)loadView
{
    self.view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 240)];
    self.view.backgroundColor = [UIColor greenColor];
    self.title = @"SecondVC";

    self.navigationItem.hidesBackButton = YES;
    UIBarButtonItem *leftBtn = [[UIBarButtonItem alloc] initWithTitle:@"FirstLevel" style:UIBarButtonItemStyleBordered target:self action:@selector(leftBtnSelected:)];
    self.navigationItem.leftBarButtonItem = leftBtn;
}

- (void) leftBtnSelected:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

UINavigationItem initWithTitle example.
// in .h file
@property (nonatomic, retain) UINavigationBar *navBar;

// in .m file just below @implementation
@synthesize navBar;

// within .m method
navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 48.0f)];
navBar.barStyle = UIBarStyleBlack;

UINavigationItem *title = [[UINavigationItem alloc] initWithTitle:@"Nav Bar Title"];

UIBarButtonItem *leftButton = [[UIBarButtonItem alloc]
                       initWithTitle:@"Back"
                               style:UIBarButtonItemStylePlain
                              target:nil
                              action:@selector(backButtonSelected:)];

title.leftBarButtonItem = leftButton;

UIBarButtonItem *rightButton = [[UIBarButtonItem alloc]
         initWithBarButtonSystemItem:UIBarButtonSystemItemAction
                              target:nil
                              action:@selector(showActionSheet:)];

title.rightBarButtonItem = rightButton;

[navBar pushNavigationItem:title animated:YES];

[self.view addSubview:navBar];

End of UINavigationItem initWithTitle example article.

UINavigationItem titleView example in Objective C (iOS).


UINavigationItem titleView

A custom view displayed in the center of the navigation bar when the receiver is the top item.

@property(nonatomic, retain) UIView *titleView

Discussion of [UINavigationItem titleView]
If this property value is nil, the navigation item’s title is displayed in the center of the navigation bar when the receiver is the top item. If you set this property to a custom title, it is displayed instead of the title. This property is ignored if leftBarButtonItem is not nil.[UINavigationItem titleView]

Custom views can contain buttons. Use the buttonWithType: method in UIButton class to add buttons to your custom view in the style of the navigation bar. Custom title views are centered on the navigation bar and may be resized to fit.

The default value is nil.

UINavigationItem titleView example.
Consider using UINib - it was exposed in iOS 4.0. It double perf since it caches the nib for you.

UINib *nib = [UINib nibWithNibName:@"TestView" bundle:nil];
UIView *myView = [[nib instantiateWithOwner:self options:nil] objectAtIndex:0]];
The objectAtIndex refers to the top level views in the NIB - typically there's one (index 0) but if there's many, you need to provide the index.

Once you have the view you can assign it to the navigationItem titleView

self.navigationItem.titleView = myView;
[myview release];

Example of [UINavigationItem titleView].
UIFont* font = [UIFont fontWithName:@"Bitsumishi" size:20];
CGSize maximumLabelSize = CGSizeMake(296,9999);
CGSize expectedLabelSize = [title sizeWithFont:font constrainedToSize:maximumLabelSize lineBreakMode:UILineBreakModeCharacterWrap];
CGRect frame = CGRectMake(0, 0, expectedLabelSize.width, expectedLabelSize.height);
UILabel *label = [[[UILabel alloc] initWithFrame:frame] autorelease];
label.font = font;
label.textAlignment = UITextAlignmentLeft;
label.text = title;
self.titleView = label;

UINavigationItem titleView example.
label = [[UILabel alloc] init];
label.backgroundColor = [UIColor clearColor];
label.font = [ UIFont fontWithName: @"XXII DIRTY-ARMY" size: 32.0 ];
label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.0f];
label.textAlignment = UITextAlignmentCenter;
label.textColor =[UIColor orangeColor];
//label.text=categoryTitle;
CGFloat verticalOffset = 2;
NSString *reqSysVer = @"5.0";
NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
if ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending)          
{
    if (categoryTitle.length > 8)
    {
    label.frame = CGRectMake(0, 0, 300, 44);
    }else {
        label.frame = CGRectMake(0, 0, 80, 44);
    }

    self.navigationItem.titleView = label; 
     self.navigationItem.title=label.text;
    [[UINavigationBar appearance] setTitleVerticalPositionAdjustment:verticalOffset   forBarMetrics:UIBarMetricsDefault];
     [[UIBarButtonItem appearance] setTintColor:[UIColor newBrownLight]];

}

End of UINavigationItem titleView example article.

UINavigationItem setTitle example in Objective C (iOS).


UINavigationItem setTitle

The navigation item’s title displayed in the center of the navigation bar.

@property(nonatomic, copy) NSString *title

Discussion of [UINavigationItem setTitle]
The default value is nil.

When the receiver is on the navigation item stack and is second from the top—in other words, its view controller manages the views that the user would navigate back to—the value in this property is used for the back button on the top-most navigation bar. If the value of this property is nil, the system uses the string “Back” as the text of the back button.

UINavigationItem setTitle example.
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.

Example of [UINavigationItem setTitle].
CGRect navBarFrame = CGRectMake(0, 0, self.tableView.frame.size.width, 44.0);
UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:navBarFrame];

UINavigationItem *navItem = [UINavigationItem alloc];
navItem.title = @"Your Title";

[navBar pushNavigationItem:navItem animated:false];

UINavigationItem setTitle example.
@synthesize navBar;
-(void)viewWillAppear:(BOOL)animated {
[self.navBar setTitle:@"Sign In"];
[self.navigationController setNavigationBarHidden:NO animated:animated];
}

End of UINavigationItem setTitle example article.

UINavigationItem title example in Objective C (iOS).


UINavigationItem title

The navigation item’s title displayed in the center of the navigation bar.

@property(nonatomic, copy) NSString *title

Discussion of [UINavigationItem title]
The default value is nil.

When the receiver is on the navigation item stack and is second from the top—in other words, its view controller manages the views that the user would navigate back to—the value in this property is used for the back button on the top-most navigation bar. If the value of this property is nil, the system uses the string “Back” as the text of the back button.

UINavigationItem title example.
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.

Example of [UINavigationItem title].
CGRect navBarFrame = CGRectMake(0, 0, self.tableView.frame.size.width, 44.0);
UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:navBarFrame];

UINavigationItem *navItem = [UINavigationItem alloc];
navItem.title = @"Your Title";

[navBar pushNavigationItem:navItem animated:false];

UINavigationItem title example.
@synthesize navBar;
-(void)viewWillAppear:(BOOL)animated {
[self.navBar setTitle:@"Sign In"];
[self.navigationController setNavigationBarHidden:NO animated:animated];
}

End of UINavigationItem title example article.

UINavigationItem rightBarButtonItems example in Objective C (iOS).


UINavigationItem rightBarButtonItems

An array of custom bar button items to display on the right side of the navigation bar when the receiver is the top navigation item.

@property(nonatomic, copy) NSArray *rightBarButtonItems

Discussion of [UINavigationItem rightBarButtonItems]
This array can contain 0 or more bar button items to display on the right side of the navigation bar. Items are displayed right-to-left in the same order as they appear in the array. Thus, the first item in the array is the rightmost item and other items are added to the left of the previous item.[UINavigationItem rightBarButtonItems]

If there is not enough room to display all of the items in the array, those that would overlap the title view (if present) or the buttons on the left side of the bar are not displayed.

The first item in the array can also be set using the rightBarButtonItem property.

UINavigationItem rightBarButtonItems example.
UINavigationBar *navBarView = [[UINavigationBar alloc] initWithFrame: CGRectMake(0.0f, 0.0f, 320.0f, 42.0f)];
    navBarView.tintColor= [UIColor colorWithRed:90.0/255.0f green:53.0/255.0f blue:45.0/255.0f alpha:1.0];

    UIBarButtonItem *left=[[UIBarButtonItem alloc]initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:self action:@selector(backView)];
    UIBarButtonItem *right=[[UIBarButtonItem alloc]initWithTitle:@"Save" style:UIBarButtonItemStylePlain target:self action:@selector(SaveImage)];
    UIBarButtonItem *Add=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(AddComment:)];

    UINavigationItem *navigationItem = [[UINavigationItem alloc] init];
    navigationItem.leftBarButtonItem = left;
    NSMutableArray *buttonArray=[[NSMutableArray alloc]initWithCapacity:2];
    [buttonArray addObject:right];
    [buttonArray addObject:Add];
    navigationItem.rightBarButtonItems = buttonArray;
    [navBarView pushNavigationItem:navigationItem animated:NO];
[self.view addSubView:navBarView];

Example of [UINavigationItem rightBarButtonItems].
UIBarButtonItem *btnShare = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(share)];
UIBarButtonItem *btnRefresh = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(loadBeeconSite)];
[self.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects:btnShare, btnRefresh, nil]];

UINavigationItem rightBarButtonItems example.
// Two buttons at the right side of nav bar
UIBarButtonItem *addAttachButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addAttachmentClicked:)];
UIBarButtonItem *sendButton = [[UIBarButtonItem alloc] initWithTitle:LS(@"Send") style:UIBarButtonItemStyleBordered target:self action:@selector(sendClicked:)];
self.navigationItem.rightBarButtonItems = @[addAttachButton,sendButton];

End of UINavigationItem rightBarButtonItems example article.

UINavigationItem rightBarButtonItem example in Objective C (iOS).


UINavigationItem rightBarButtonItem

A custom bar button item displayed on the right of the navigation bar when the receiver is the top navigation item.

@property(nonatomic, retain) UIBarButtonItem *rightBarButtonItem

Discussion of [UINavigationItem rightBarButtonItem]
In iOS 5.0 and later, the contents of this property always refer to the first bar button item in the rightBarButtonItems array. Assigning a new value to this property replaces the first item in the rightBarButtonItems array with the new value. Setting this property to nil removes the first item in the array. If the bar button item is already in the array, it is moved from its current location to the front of the array.

Prior to iOS 5.0, this property contained the single bar item to display on the right side of the navigation bar.

Availability
Available in iOS 2.0 and later.

UINavigationItem rightBarButtonItem example.
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:@"Done"
    style:UIBarButtonItemStyleDone target:nil action:nil];
UINavigationItem *item = [[UINavigationItem alloc] initWithTitle:@"Title"];
item.rightBarButtonItem = rightButton;
item.hidesBackButton = YES;
[bar pushNavigationItem:item animated:NO];
[rightButton release];
[item release];
But normally you would have a navigation controller, enabling you to write:

UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:@"Done"
    style:UIBarButtonItemStyleDone target:nil action:nil];
self.navigationItem.rightBarButtonItem = rightButton;
[rightButton release];

Example of [UINavigationItem rightBarButtonItem].
UIView *parentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, myWidth, myHeight)];
// make UIView customView1... (UILabel, UIButton, etc.) with desired frame and settings
[parentView addSubview:customView1];
[customView1 release];
// make UIView customView2... (UILabel, UIButton, etc.) with desired frame and settings
[parentView addSubview:customView2];
[customView2 release];
UIBarButtonItem *customBarButtomItem = [[UIBarButtonItem alloc] initWithCustomView:parentView];
[parentView release];
self.navigationItem.rightBarButtonItem = customBarButtomItem;
[customBarButtomItem release];

UINavigationItem rightBarButtonItem example.
UIView *containerView = [[UIView alloc] initWithFrame:CGRectMake(89,40,100,30)];
containerView.layer.borderColor = [[UIColor redColor] CGColor];
containerView.layer.borderWidth = 1.0;
UIImage *image = [UIImage imageNamed:@"nav-icon.png"];
UIButton *navigationButton = [UIButton buttonWithType:UIButtonTypeCustom];
[navigationButton setFrame:CGRectMake(67,0,25,25)];
[navigationButton setImage:image forState:UIControlStateNormal];
[containerView addSubview:navigationButton];

UIBarButtonItem *navigationBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:containerView];

self.navigationItem.rightBarButtonItem = navigationBarButtonItem;

End of UINavigationItem rightBarButtonItem example article.

UINavigationItem setPrompt example in Objective C (iOS).


UINavigationItem setPrompt

A single line of text displayed at the top of the navigation bar.

@property(nonatomic, copy) NSString *prompt

Discussion of [UINavigationItem setPrompt]
The default value is nil.

UINavigationItem setPrompt example.
UIView                      *viewContainingSpinner;
    UIActivityIndicatorView     *activityIndicatorView;
    UIBarButtonItem             *activityButtonItem;
    UIBarButtonItem             *rightBarButtonItem;

    // Configuring the title and the prompt title of the navigation bar
    [self.navigationItem setTitle:@"MobileMe"];
    [self.navigationItem setPrompt:@"Vérification du compte MobileMe"];

    // We will create a UIBarButtonItem that has a custom view (viewContainingSpinner).
    // A subview of viewContainingSpinner will be a UIActivityIndicatorView (activityIndicatorView)
    // We need to have this "intermediate" view to position the spinner at the right position (the UIBarButtonItem ignores the origin and height of its custom view)
    viewContainingSpinner = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 60, 85)];
    activityIndicatorView = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(20, 0, 20, 20)];
    [viewContainingSpinner addSubview:activityIndicatorView];
    [activityIndicatorView startAnimating];
    [activityIndicatorView release];

    activityButtonItem = [[UIBarButtonItem alloc] initWithCustomView:viewContainingSpinner];
    self.navigationItem.leftBarButtonItem = activityButtonItem;
    [viewContainingSpinner release];
    [activityButtonItem release];

    // Finally, configuring the right button
    rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Enregistrer" style:UIBarButtonItemStylePlain target:nil action:nil];
    [rightBarButtonItem setEnabled:NO];
    self.navigationItem.rightBarButtonItem = rightBarButtonItem;
    [rightBarButtonItem release];

Example of [UINavigationItem setPrompt].
UINavigationBar *bar = picker.navigationBar;
UINavigationItem *navItem = bar.topItem;
navItem.prompt = @"Some new prompt";

UINavigationItem setPrompt example.
self.navigationItem.prompt = NSLocalizedString(@\"Please select the appropriate media type:\", @\"Page Five Prompt\");

End of UINavigationItem setPrompt example article.

UINavigationItem prompt example in Objective C (iOS).


UINavigationItem prompt

A single line of text displayed at the top of the navigation bar.

@property(nonatomic, copy) NSString *prompt

Discussion of [UINavigationItem prompt]
The default value is nil.

UINavigationItem prompt example.
UIView                      *viewContainingSpinner;
    UIActivityIndicatorView     *activityIndicatorView;
    UIBarButtonItem             *activityButtonItem;
    UIBarButtonItem             *rightBarButtonItem;

    // Configuring the title and the prompt title of the navigation bar
    [self.navigationItem setTitle:@"MobileMe"];
    [self.navigationItem setPrompt:@"Vérification du compte MobileMe"];

    // We will create a UIBarButtonItem that has a custom view (viewContainingSpinner).
    // A subview of viewContainingSpinner will be a UIActivityIndicatorView (activityIndicatorView)
    // We need to have this "intermediate" view to position the spinner at the right position (the UIBarButtonItem ignores the origin and height of its custom view)
    viewContainingSpinner = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 60, 85)];
    activityIndicatorView = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(20, 0, 20, 20)];
    [viewContainingSpinner addSubview:activityIndicatorView];
    [activityIndicatorView startAnimating];
    [activityIndicatorView release];

    activityButtonItem = [[UIBarButtonItem alloc] initWithCustomView:viewContainingSpinner];
    self.navigationItem.leftBarButtonItem = activityButtonItem;
    [viewContainingSpinner release];
    [activityButtonItem release];

    // Finally, configuring the right button
    rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Enregistrer" style:UIBarButtonItemStylePlain target:nil action:nil];
    [rightBarButtonItem setEnabled:NO];
    self.navigationItem.rightBarButtonItem = rightBarButtonItem;
    [rightBarButtonItem release];

Example of [UINavigationItem prompt].
UINavigationBar *bar = picker.navigationBar;
UINavigationItem *navItem = bar.topItem;
navItem.prompt = @"Some new prompt";

UINavigationItem prompt example.
self.navigationItem.prompt = NSLocalizedString(@\"Please select the appropriate media type:\", @\"Page Five Prompt\");

End of UINavigationItem prompt example article.

UINavigationItem leftBarButtonItems example in Objective C (iOS).


UINavigationItem leftBarButtonItems

An array of custom bar button items to display on the left side of the navigation bar when the receiver is the top navigation item.

@property(nonatomic, copy) NSArray *leftBarButtonItems

Discussion of [UINavigationItem leftBarButtonItems]
This array can contain 0 or more bar items to display on the left side of the navigation bar. Items can include fixed-width and flexible-width spaces. If the leftItemsSupplementBackButton property is YES, the items are displayed to the right of the back button, otherwise the items replace the back button and start at the left edge of the bar. Items are displayed left-to-right in the same order as they appear in the array.[UINavigationItem leftBarButtonItems]

If there is not enough room to display all of the items in the array, those that would overlap the title view (if present) or the buttons on the right side of the bar are not displayed.

The first item in the array can also be set using the leftBarButtonItem property.

UINavigationItem leftBarButtonItems example.
You need to add UIBarButtonItem instance to a UINavigationItem, not to a UINavigationBar. So you can do this as:

NSArray *buttonArray = [NSArray arrayWithObjects:logoButton, logoButton2, logoButton3, nil];
self.navigationItem.leftBarButtonItems = buttonArray;
If you want your buttons on the right, use rightBarButtonItems.

Example of [UINavigationItem leftBarButtonItems].
UIBarButtonItem *backButtonItem // Assume this exists, filled with our custom view

// Create a negative spacer to go to the left of our custom back button,
// and pull it right to the edge:
UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc]
    initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
    target:nil action:nil];
negativeSpacer.width = -5;
// Note: We use 5 above b/c that's how many pixels of padding iOS seems to add

// Add the two buttons together on the left:
self.navigationItem.leftBarButtonItems = [NSArray
    arrayWithObjects:negativeSpacer, backButtonItem, nil];

UINavigationItem leftBarButtonItems example.
m_navBar = [[UINavigationBar alloc] init];
  [m_navBar setFrame:CGRectMake(0,0,self.view.bounds.size.width,52)];
  [self.view addSubview:m_navBar];

  UIBarButtonItem *barButton = [[UIBarButtonItem alloc]
                                initWithBarButtonSystemItem:UIBarButtonSystemItemAction
                                target:self
                                action:@selector(buttonSettingClicked)];

  UINavigationItem* navItem = [[UINavigationItem alloc] initWithTitle:@"MyItem"];
  [m_navBar pushNavigationItem:navItem animated:NO];

  navItem.leftBarButtonItems = @[barButton, barButton];

End of UINavigationItem leftBarButtonItems example article.

UINavigationItem leftBarButtonItem example in Objective C (iOS).


UINavigationItem leftBarButtonItem

A custom bar button item displayed on the left of the navigation bar when the receiver is the top navigation item.

@property(nonatomic, retain) UIBarButtonItem *leftBarButtonItem

Discussion of [UINavigationItem leftBarButtonItem]
In iOS 5.0 and later, the contents of this property always refer to the first bar button item in the leftBarButtonItems array. Assigning a new value to this property replaces the first item in the leftBarButtonItems array with the new value. Setting this property to nil removes the first item in the array. If the bar button item is already in the array, it is moved from its current location to the front of the array.

Prior to iOS 5.0, this property contained the single bar item to display on the left side of the navigation bar instead of the back button.

UINavigationItem leftBarButtonItem example.
Hiding UInavigationItem's bar button
This works I tried it myself

self.navigationItem.leftBarButtonItem = nil;
self.navigationItem.hidesBackButton = YES;      

Example of [UINavigationItem leftBarButtonItem].
CGRect rect = CGRectMake(10, 0, 30, 30);
self.backButton = [[UIButton alloc] initWithFrame:rect];
[self.backButton setImage:[UIImage imageNamed:@"back_arrow.png"]
                 forState:UIControlStateNormal];
self.backButton.contentMode = UIViewContentModeCenter;
[self.backButton addTarget:self
                    action:@selector(backButtonAction:)
          forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem *backButtonItem = [[UIBarButtonItem alloc] initWithCustomView:self.backButton];
self.navigationItem.leftBarButtonItem = backButtonItem;
self.navigationItem.hidesBackButton = YES;

UINavigationItem leftBarButtonItem example.
   //Next Button
    btnNext = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:
               UIBarButtonSystemItemPlay  target:self action:@selector(next:)];
    [items addObject:btnNext];

    [tool setItems:items];
    tool.barStyle =UIBarStyleDefault;
    tool.backgroundColor = [UIColor clearColor];

    //self.navigationItem.leftBarButtonItem.customView = tool;
    //self.navigationItem.titleView = tool;
    self.navigationItem.leftBarButtonItem =  [[UIBarButtonItem alloc] initWithCustomView:tool];

End of UINavigationItem leftBarButtonItem example article.

UINavigationItem hidesBackButton example in Objective C (iOS).


UINavigationItem hidesBackButton

A Boolean value that determines whether the back button is hidden.

@property(nonatomic, assign) BOOL hidesBackButton

Discussion of [UINavigationItem hidesBackButton]
When set to YES, the back button is hidden when this navigation item is the top item. This is true regardless of the value in the leftItemsSupplementBackButton property. When set to NO, the back button is shown if it is still present. (It can be replaced by values in either the leftBarButtonItem or leftBarButtonItems properties.) The default value is NO.

UINavigationItem hidesBackButton example.
@implementation BVC

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"I am B";
}

- (void) viewWillAppear:(BOOL)animated{
    self.navigationItem.hidesBackButton = YES;
}

- (IBAction)pushB:(UIButton *)sender{
    CVC *cvc = [[CVC alloc] initWithNibName:@"CVC" bundle:nil];
    [self.navigationController pushViewController:cvc animated:YES];
    [cvc release];
}
@end

@implementation CVC

- (void) viewWillAppear:(BOOL)animated{
    self.navigationItem.hidesBackButton = NO;
}
@end

Example of [UINavigationItem hidesBackButton].
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:@"Done"
    style:UIBarButtonItemStyleDone target:nil action:nil];
UINavigationItem *item = [[UINavigationItem alloc] initWithTitle:@"Title"];
item.rightBarButtonItem = rightButton;
item.hidesBackButton = YES;
[bar pushNavigationItem:item animated:NO];
[rightButton release];
[item release];

UINavigationItem hidesBackButton example.
- (void)loadView
{
    self.view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 240)];
    self.view.backgroundColor = [UIColor greenColor];
    self.title = @"SecondVC";

    self.navigationItem.hidesBackButton = YES;
    UIBarButtonItem *leftBtn = [[UIBarButtonItem alloc] initWithTitle:@"FirstLevel" style:UIBarButtonItemStyleBordered target:self action:@selector(leftBtnSelected:)];
    self.navigationItem.leftBarButtonItem = leftBtn;
}

- (void) leftBtnSelected:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

End of UINavigationItem hidesBackButton example article.

UINavigationItem setBackBarButtonItem example in Objective C (iOS).


UINavigationItem setBackBarButtonItem

The bar button item to use when a back button is needed on the navigation bar.

@property(nonatomic, retain) UIBarButtonItem *backBarButtonItem

Discussion of [UINavigationItem setBackBarButtonItem]
When this navigation item is immediately below the top item in the stack, the navigation controller derives the back button for the navigation bar from this navigation item. When this property is nil, the navigation item uses the value in its title property to create an appropriate back button. If you want to specify a custom image or title for the back button, you can assign a custom bar button item (with your custom title or image) to this property instead. When configuring your bar button item, do not assign a custom view to it; the navigation item ignores custom views in the back bar button anyway.

The default value of this property is nil.

UINavigationItem setBackBarButtonItem example.
If you want that any backBarButtonItem of your application has the same title a good approach is to subclass UINavigationController and override - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated to replace the back button.

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    UIBarButtonItem *_backButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"BackButtonLabel", "")
                                                                    style:UIBarButtonItemStyleDone
                                                                   target:nil
                                                                   action:nil];
    viewController.navigationItem.backBarButtonItem = _backButton;
    _backButton = nil;
    [_backButton release];

    [super pushViewController:viewController animated:animated];
}
By this way every back button in your application will have the same title.

I hope this will be helpful for anyone else.

Example of [UINavigationItem setBackBarButtonItem].
This should be placed in the method that calls the ViewController titled "NewTitle". Right before the push or popViewController statement.

UIBarButtonItem *newBackButton = [[UIBarButtonItem alloc] initWithTitle: @"NewTitle" style: UIBarButtonItemStyleBordered target: nil action: nil];

[[self navigationItem] setBackBarButtonItem: newBackButton];

[newBackButton release];

UINavigationItem setBackBarButtonItem example.
UIImage *backButtonImage = [UIImage imageNamed:@"Graphics/Shared/navigation_back_button.png"];
CGRect frameimg = CGRectMake(0, 0, backButtonImage.size.width, backButtonImage.size.height);
UIButton *someButton = [[UIButton alloc] initWithFrame:frameimg];
[someButton setBackgroundImage:backButtonImage forState:UIControlStateNormal];
// you have to do your own backButtonAction to pop the view controller, b.t.w.
[someButton addTarget:self action:@selector(backButtonAction:)
     forControlEvents:UIControlEventTouchUpInside];
[someButton setShowsTouchWhenHighlighted:YES];

UIBarButtonItem *backButton =[[UIBarButtonItem alloc] initWithCustomView:someButton];
[someButton release];

self.navigationItem.backBarButtonItem = backButton;

End of UINavigationItem setBackBarButtonItem example article.