Alex Rivera | Logout

How to add 2 buttons into the UINavigationbar on the right side without IB?

Asked 2009-11-26T13:14:11.627
86

How can I add 2 buttons into the UINavigationBar without XIB?
The 2 buttons should be aligned on the right side of the UINavigationBar.

I know how I can add one button, but how about two?

Edit
Report

1 Answer

2

You don“t have to add two buttons. You just need to add

UIBarButtonSystemItemFlexibleSpace 

not

UIBarButtonSystemItemFixedSpace

and a button, so that it will be on right side.

Like this:

UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 40)];
toolbar.barStyle = UIBarStyleBlackTranslucent;

UIBarButtonItem *spaceButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];

UIBarButtonItem *infoButtonItem1 = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(empresaTextFieldDone)];    

toolbar.items = [NSArray arrayWithObjects: spaceButton, infoButtonItem1, nil];   
answered 2012-09-05T14:58:04.420

Your Answer