2010-09-26 46 views
0

我想在導航欄的兩端都有兩個按鈕(在iPad的Detail View Controller中)。iPad中的UIToolbar

所以我創建了兩個UIToolbars,並將它們設置爲Left & RightBarButtonItems。

但是,NavigationBar中有一些顏色變化。

爲了您的理解附加圖片。

alt text

alt textalt text

我使用的代碼,

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]; 

你能幫我避免這種顏色的變化?

是否有任何其他方式有這樣的按鈕,而不使用UIToolbar?

謝謝,

Gopi。

回答

1

只是刪除導航欄和添加工具欄,爲什麼你添加工具欄導航欄?

+0

我需要顯示一些文檔,所以我需要在導航欄的標題中顯示文檔的名稱。 – gopikrishnan 2010-09-26 10:58:12

+0

爲什麼你不能在工具欄中顯示標題? – RolandasR 2010-09-26 16:51:15

+0

如何在工具欄中添加標題?我相信我不能在工具欄上有標籤。我無法找到任何其他方式來實施它。讓我知道如果我錯過了什麼..謝謝GameBit。 – gopikrishnan 2010-09-27 06:29:13

0

找到解決方案!代碼是正確的,但一個小錯誤。必須將高度設置爲44,而不是45.我這樣做,它似乎適合現有的NavigationBar。

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

適合我。 。無論如何,我轉移到單一工具欄的方法。

希望這有助於一個。

祝您有美好的一天!

Gopi。

1

爲了達到同樣的目的,使用segment controll,將它設置在左或右barbutton的視圖中,一旦你選擇了一個segmet,在幾秒鐘後取消選擇它,比如0.3secs,它看起來不錯,沒有顏色變化,看起來像一個導航欄的一部分