我想用我的应用程序在我的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