我想用我的應用程序在我的UINavigationBar中添加一個漸變。我發現它在https://github.com/chroman/CRGradientNavigationBar自定義導航欄給我雙導航欄iN查看
我的應用程序是一個選項卡欄控制器應用程序,其中每個選項卡是一個NavigationController。我有我的代碼設置爲:
UINavigationController *navigationController = [[UINavigationController alloc] initWithNavigationBarClass:[CRGradientNavigationBar class] toolbarClass:nil];
UIColor *firstColor = [UIColor colorWithRed:255.0f/255.0f green:42.0f/255.0f blue:104.0f/255.0f alpha:1.0f];
UIColor *secondColor = [UIColor colorWithRed:255.0f/255.0f green:90.0f/255.0f blue:58.0f/255.0f alpha:1.0f];
NSArray *colors = [NSArray arrayWithObjects:firstColor, secondColor, nil];
// or NSArray *colors = [NSArray arrayWithObjects:(id)UIColorFromRGB(0xf16149).CGColor, (id)UIColorFromRGB(0xf14959).CGColor, nil];
[[CRGradientNavigationBar appearance] setBarTintGradientColors:colors];
[[navigationController navigationBar] setTranslucent:NO]; // Remember, the default value is YES.
[navigationController setViewControllers:@[tabBarController]];
[self.window setRootViewController:navigationController];
但是,我得到雙倍導航欄,以標題和被添加到第二uibarbuttonitems,而不是一個梯度。有什麼建議麼?
這正是我如何設置。我的根是一個標籤欄控制器。每個標籤都有一個導航控制器。我的問題是,當從github添加這個子類的NavigationBar時,它並沒有爲每個選項卡取代導航控制器的導航欄,而只是在其上添加一個新的導航欄。 – user717452 2015-01-19 16:10:20
對不起,我正在編輯此評論 – 2015-01-21 20:03:22
在您提供的代碼中,看起來好像標籤欄控制器是導航控制器上的視圖控制器,並且導航控制器已設置爲窗口的根視圖控制器: [navigationController setViewControllers:@ [tabBarController]]; [self.window setRootViewController:navigationController]; – 2015-01-29 17:18:54