views:

137

answers:

2

Hi all,

I wanted to have two buttons on the both end of Navigation Bar (in iPad's Detail View Controller).

So I created two UIToolbars and I set the them as Left&RightBarButtonItems.

But, There is some color variation in the NavigationBar.

Attached images for your understanding.

alt text

alt text alt text

the code I used ,

 UIToolbar *leftToolbar =[[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 200, 45)];
 NSMutableArray *lItems = [[NSMutableArray alloc] initWithArray:[leftToolbar items]];
 UIBarButtonItem *lb1 =[[UIBarButtonItem alloc]initWithTitle:@"Home"style:UIBarButtonItemStyleBordered target:self action:@selector(home:) ];

 UIBarButtonItem *lb2 =[[UIBarButtonItem alloc]initWithTitle:@"New Document"style:UIBarButtonItemStyleBordered target:self action:@selector(newDoc:) ];

 [lItems insertObject:lb1 atIndex:0];
 [lItems insertObject:lb2 atIndex:1];
 [leftToolbar setItems:lItems animated:YES];
 [lItems release];



  leftToolbar.barStyle =UIBarStyleBlackTranslucent;
 leftToolbar.tintColor=[UIColor clearColor];
 self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc] initWithCustomView:leftToolbar];

Can you help me to avoid this color variation?

Is there any other way to have buttons like this, without using UIToolbar?

Thanks ,

Gopi.

+1  A: 

just remove navigation bar and add tool bar, why you adding toolbar to navigation bar?

GameBit
I need to show some documents, So I need to display the name of the document in the title of the Navigation bar.
GopiKrishnAn
So, I need Navigation bar.
GopiKrishnAn
why you cant show title in toolbar?
GameBit
How can i add titles in Toolbar? I believe I cant have Labels in toolbar. I couldnt find any other way to implement it. let me know if i miss something..Thanks GameBit.
GopiKrishnAn
here you have 2 choices: 1) just put UILabel on top 2) add UITabButton with plain style
GameBit
UIBarButtonItem wtih plain style is a good one.Finally I have to use that if I dont find any. It glows when i tap on that. So thinking of finding some better way to do that.I have seen some apps that have the same format of my Top bar (as given in the above image) , and they dont glow when tapped. So there should be some other way that I am unaware of. UILabel can't be added in UIToolbar , I tried it already. Any suggestions on my views? Thanks GameBit.
GopiKrishnAn
why UILabel can't be added? just [_toolbar addSubview:...] and that's it (don't do it in IB).
GameBit
Label is getting added. but not as a part of Toolbar.It is added separately .I tried to add it as an "item" in Toolbar, that landed in an error,"[UILabel view] unknown selector sent to. . .etc"
GopiKrishnAn
how come its not part of toolbar? UILabel *titleLabel = [[UILabel alloc] initWithFrame:[toolBar bounds]]; [titleLabel setTextAlignment:UITextAlignmentCenter]; [titleLabel setBackgroundColor:[UIColor clearColor]]; [titleLabel setText:@"My Title"]; [toolBar addSubview:titleLabel]; [titleLabel release];
GameBit
This works great!! Thanks a lot GameBit!!
GopiKrishnAn
A: 

Found the solution ! code is correct, but one small bug. Have to set the height to 44, not 45. I did this and it seems to fit over the existing NavigationBar.

UIToolbar *leftToolbar =[[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 200, 44)];

Works for me . . Anyway I moved to the Single tool bar method.

Hope this helps some one.!!

Have a great day!!

Gopi.

GopiKrishnAn