gopikrishnan
gopikrishnan

Reputation: 198

UIToolbar in iPad

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.

Upvotes: 0

Views: 2615

Answers (3)

Nikesh K
Nikesh K

Reputation: 621

To achieve the same, use segment controll, set it in Left or right barbutton's view, once you select a segmet, deselect it after few seconds, say 0.3secs, it looks good, no color vairations, it looks like a part of Navigation bar

Upvotes: 1

gopikrishnan
gopikrishnan

Reputation: 198

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.

Upvotes: 0

RolandasR
RolandasR

Reputation: 3047

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

Upvotes: 1

Related Questions