簡體   English   中英

為什么 tintColor 在 iOS7 上的導航欄或工具欄上不起作用

[英]Why tintColor doesn't work on navigation bar or toolbar on iOS7

在 iPad 的 iOS7 上,首先我設置了一個模態視圖控制器,大小為 320 * 460,然后,在這個模態視圖控制器中,我展示了另一個導航視圖控制器,然后是導航欄和工具欄的色調顏色呈現的導航控制器變為灰色。 我試圖設置導航欄和工具欄的色調顏色,但它不起作用。

然后我嘗試直接呈現導航控制器,然后所有色調顏色都適用於導航欄和工具欄。

我已經嘗試使用導航欄和工具欄的barTintColor屬性,它有效。

我不知道會發生什么。

更新

首先,我定義了一個視圖控制器:modalViewController 像這樣呈現模態視圖控制器:

if (DeviceIsPad()) // DeviceIsPad is a method defined somewhere to tell that the device is an iPad.
    modaViewController.modalPresentationStyle = UIModalPresentationFormSheet;

//here self is a normal view controller
[self presentViewController:modalViewController animated:YES completion:NULL];

其次,定義一個導航視圖控制器: navigationController 像這樣呈現導航控制器:

if (DeviceIsPad())
    navigationController.modalPresentationStyle = UIModalPresentationCurrentContext;

// here self means the modalViewController mentioned above
[self presentViewController:navigationController animated:YES completion:nil];

我在 navigationController 的“viewDidLoad”方法中設置了導航欄和工具欄欄項目。

默認情況下,當導航視圖控制器出現時,所有工具欄按鈕項目(這些項目僅使用基本標題構建,如CancelOK )變為灰色。

同時,我嘗試設置tool barnavigation bar tintColor 使用實例方法和外觀方法(如[[UIToolBar appearance] setTintColor:[UIColor blueColor]] )。 但它仍然不起作用。

然后我嘗試直接從普通視圖控制器中使用UIModalPresentationFormSheet樣式呈現上面提到的navigationViewController ,然后導航欄和工具欄的所有 tintColor 變成藍色(系統藍色)。

發生這種情況是因為 Apple 假設我們不會呈現超過 1 個視圖控制器並將背景和所有欄按鈕項(不知道為什么)變暗作為將焦點放在最前面的視圖的默認行為。

要解決此問題,您只需在應用程序窗口的 DidFinishLaunchingWithOptions 中將 tintAdjustmentMode 強制設為 Normal。

self.window.tintAdjustmentMode = UIViewTintAdjustmentModeNormal;

嘗試設置

 [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"NavBarBGTile.png"] forBarPosition:UIBarPositionTopAttached barMetrics:UIBarMetricsDefault];

其中 NavBarBGTile.png 是一個 1X1px 平鋪圖像,其顏色為您想要的導航欄顏色

  [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];

用你想要的任何東西替換白色

這些行應該放在應用程序啟動的開始處

試試這個代碼:

UIView *masterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 260)];
UIToolbar *pickerToolbar = [self createPickerToolbarWithTitle:@"Surgeons"];
pickerToolbar.barTintColor= [UIColor blueColor];
pickerToolbar.translucent=YES;
[masterView addSubview:pickerToolbar];
[masterView addSubview:pickerViewObj];
UIViewController *viewController = [[UIViewController alloc] initWithNibName:nil bundle:nil];
viewController.view = masterView;
viewController.contentSizeForViewInPopover = viewController.view.frame.size;
self.popoverController =[[UIPopoverController alloc] initWithContentViewController:viewController];

暫無
暫無

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

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