簡體   English   中英

在ipad上的Popover控制器中顯示時,更改UIToolbar及其按鈕的顏色

[英]Changing colours of a UIToolbar + it's buttons when presented in a Popover Controller on the ipad

在iPhone和iPad上,我都需要在導航欄的右側顯示兩個按鈕。 我正在使用以下代碼片段進行此操作:

UIToolbar *rightBarButtons = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 92, 44.01)];
UIBarButtonItem *send = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction 
                                                                      target:self 
                                                                      action:@selector(send)];
[send setStyle:UIBarButtonItemStyleBordered];
UIBarButtonItem *add =  [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd 
                                                                      target:self
                                                                      action:@selector(addRecipe:)];
[add setStyle:UIBarButtonItemStyleBordered];
NSArray *buttons = [[NSArray alloc] initWithObjects:send,add,nil];
[send release];
[add release];
[rightBarButtons setItems:buttons];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightBarButtons];
[buttons release];
[rightBarButtons release];

在iPhone上,顏色很好,而在iPad上,在橫向模式下,顏色很好,因為它們是灰色的。 但是,在縱向模式下,視圖會出現在具有深黑色/藍色的彈出式控制器內部。 我的按鈕和工具欄顯示為默認灰色。

如何使工具欄按鈕匹配? 如果您不使用上面的技巧,僅按常規顯示一個按鈕,就可以處理顏色變化,我想我只需要手動實現該顏色變化,問題是,我似乎根本無法獲得顏色變化。

這似乎是一個名為barStyle的屬性,而不是我以前認為的tintColor。 最簡單的解決方案是從其他位置復制條形:

[rightBarButtons setBarStyle:self.navigationController.navigationBar.barStyle];

然后,確保樣式隨視圖更改而保持正確是相當瑣碎的。 盡管我不得不說,我非常喜歡旋轉后顯示的銀色導航欄上的深藍色黑色按鈕。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM