我知道这个话题已经有了一些线索,但它们只是部分地解决了我的问题。我设法自定义了moreNavigationController navigationBar颜色和标签颜色,请参见以下内容:

但是,通过自定义视图,我遇到了一些问题,如果您单击右侧的“编辑”,则会显示该视图。目前的情况如下:

我想实现什么?
我已经在AppDelegate中获得了对我的AppDelegate的引用
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;我还设置了这个tabBarController的委托,也调用了委托方法- (void)tabBarController:(UITabBarController *)tabBarController willBeginCustomizingViewControllers:(NSArray *)viewControllers。但从那以后我就不能给这三个控件上色了。有人给我提示了吗?
例如:
id modalViewCtrl = [[[tabBarController view] subviews] objectAtIndex:1];
if([modalViewCtrl isKindOfClass:NSClassFromString(@"UITabBarCustomizeView")] == YES)
((UINavigationBar*)[[modalViewCtrl subviews] objectAtIndex:0]).barTintColor = [UIColor redColor];此外,这也是:
- (void)tabBarController:(UITabBarController *)controller willBeginCustomizingViewControllers:(NSArray *)viewControllers {
UIView *editView = [controller.view.subviews objectAtIndex:1];
UINavigationBar *modalNavBar = [editView.subviews objectAtIndex:0];
modalNavBar.tintColor = [UIColor redColor];}
只对barTintColor不执行任何操作或崩溃,因为它“不能在UILabel上设置barTintColor”。但我不太确定如何检索不同的控件来设置它们的颜色值。
发布于 2014-01-15 17:14:22
我找到了答案。我应该记录edit_views,这样我就会看到,navigationBar位于索引1,而不是0。然后在索引2-末端有一个UITabBarButtons,我不能设置正确的颜色..。
最终代码如下所示:
- (void)tabBarController:(UITabBarController *)tabBarController
willBeginCustomizingViewControllers:(NSArray *)viewControllers
{
UIView* edit_views = [tabBarController.view.subviews objectAtIndex:1];
UINavigationBar* bar = [[edit_views subviews]objectAtIndex:1];
bar.barTintColor = [UIColor redColor];
bar.tintColor = [UIColor whiteColor];
for (int i = 3; i < [edit_views.subviews count]; i++)
{
UIButton *button = [[edit_views subviews]objectAtIndex:i];
button.tintColor = [UIColor redColor];
}
}发布于 2014-12-17 17:23:05
您可以通过使用UIView和设置窗口的tintColor来实现这一效果,而不需要混淆UIAppearance层次结构。因此,您可以将此代码放置在application:didFinishLaunchingWithOptions:中。
[self.window setTintColor:[UIColor redColor]];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
[[UINavigationBar appearance] setBarTintColor:[UIColor redColor]];如果希望在不同的视图控制器中对导航条进行不同的样式设置,还可以通过使用UIAppearance限制appearanceWhenContainedIn:代码。
https://stackoverflow.com/questions/21143498
复制相似问题