UINavigationBar外观模式不设置

我在我的appDelegate中使用下面的代码来设置我的UINavigationBar和状态栏在我的应用程序的外观:

[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]]; [[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]}]; [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; 

除非第三方模式viewController被阻止,例如Dropbox API或UIActivityViewController的邮件/消息viewController,否则此代码正确地将所有内容的外观设置为白色。 我已经包含了一些截图,以显示这些如何看。

UIActivityViewController邮件: UIActivityViewController邮件

UIActivityViewController消息: UIActivityViewController消息

Dropbox API: Dropbox API

我试图把这个

 [[UINavigationBar appearanceWhenContainedIn:[MFMailComposeViewController class], nil] setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]}]; 

以及

 [[UINavigationBar appearanceWhenContainedIn:[UIActivityViewController class], nil] setTintColor:[UIColor whiteColor]]; 

没有一个在工作。

像你一样,我一直在试图改变UIActivityViewController的外观,它是“子”控制器。 看来,在iOS7的外观API是有点bug。 UIActivityViewController可能是一个不同的过程,肯定是一个单独的窗口,所以我不觉得它的风格很麻烦。

无论如何,我发现一个有趣的方式围绕这个问题,但你的devise师可能不喜欢它。 创buildUIWindow的子类(例如:MyWindow),将其实例化为主窗口,每次使用外观API时都使用它:

 [UINavigationBar appearanceWhenContainedIn:[MyWindow class], nil].barTintColor = [UIColor redColor]; 

这样,您只会对实际属于您的应用程序的视图进行样式设置,而Apple提供的视图将保持白色/蓝色。 我想这不是你想要的解决scheme,但另一方面,它可以让用户很好的理解你的应用和系统提供了什么;)

在iOS 8中,UIActivityViewController将在应用程序的根视图控制器上显示其单独的组合控制器。

你需要inheritance你的根视图控制器(无论是UIViewController还是UINavigationController)并添加下面的代码。

 @interface UINavigationControllerBarColor : UINavigationController @end @implementation UINavigationControllerBarColor - (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion { [super presentViewController:viewControllerToPresent animated:flag completion:^{ [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; if (completion) { completion(); } }]; } @end 

然后不是在AppDelegate或故事板中初始化一个UINavigationController,而是初始化新的子类控制器。

一些其他的build议子类UIActivityViewController,但这是行不通的。

如果您想更改栏button和标题颜色,请在应用程序中使用以下内容:didFinishLaunching:

 [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]]; [[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIColor whiteColor], UITextAttributeTextColor, [UIFont systemFontOfSize:18.0f], UITextAttributeFont, nil]]; [[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setTintColor:[UIColor whiteColor]]; 

我一直在努力解决这个问题几个小时,我的结论是,所有来自UIActivityViewController活动都可能有自己的风格实现,并将视具体情况而定。

基本问题:您可以自定义某些内容以查看邮件和邮件,但是其他应用可能看起来不正确。 即:由于某种原因Facebook Messanger强制状态栏变亮。

我的build议:创build一个UIWindow子类,在你的应用程序中使用这个子类,并将UIAppearance目标UIAppearance那个窗口类,让系统的接口只是:),或者稍微改变一下颜色。

 @interface MyWindow : UIWindow @end // further in code [[UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:@[[MyWindow class]]] setTintColor:[UIColor orangeColor]]; 

仅供参考:使用UIActivityViewController时,我们几乎不能控制状态栏

希望这可以帮助。

由于到现在为止还没有解决scheme,我做了以下设置UIActivityViewController模式导航栏的颜色为白色(因为我的应用程序的导航栏颜色是蓝色),以便用户至less可以看到button:

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

当用户使用UIActivityViewController模式完成时,应用程序的主导航栏颜色将返回到蓝色。

希望有人会发布更好的解决scheme。

我find了解决scheme来更改发送取消button的文本颜色。

从这里检查我的答案。

尝试这个:

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

我有同样的问题,我用ActivityViewController的完成处理程序委托设置我的酒吧色调以白线用这一行:

 shareViewController.completionWithItemsHandler = ^(NSString *activityType, BOOL completed, NSArray *returnedItems, NSError *activityError) { [[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}]; }; 

然而,这不适用于iOS 8 …他们改变了一点完成处理程序格式,代码得到执行,但颜色没有改变。

所以为了不浪费我所有的时间,我的快速修复:

在显示共享控制器之前,我仍然用这条线改变全局颜色(带维护注释)

 [[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor darkGrayColor]}]; // Note : In ViewWillAppear the color is set back to white 

在调用UIActivityViewController的每个视图控制器中,我在viewWillAppear方法中设置获取颜色的代码。

 - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}]; } 

这虽然在代码中缺乏凝聚力,但是效果很好。

我用瓦拉普的答案来作出我自己的解决scheme。 重点是,我在presentViewController:animated:completion:设置了导航栏的tint颜色,而不是使用外观代理,而是直接为MFMailComposeViewController。

 - (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)animated completion:(void (^)(void))completion { if ([viewControllerToPresent isKindOfClass:[MFMailComposeViewController class]]) { [((MFMailComposeViewController *)viewControllerToPresent).navigationBar setTintColor:[UIColor whiteColor]]; } [super presentViewController:viewControllerToPresent animated:animated completion:^{ if ([viewControllerToPresent isKindOfClass:[MFMailComposeViewController class]]) { [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; } if (completion) { completion(); } }]; } 

我有一个特别与iMessage的问题。 不得不设置导航栏背景图像,设置色彩没有工作。 使用切片以我的颜色拉伸2×2像素的图像。

 [UINavigationBar.appearance setBackgroundImage:[UIImage imageNamed:@"red"] forBarMetrics:UIBarMetricsDefault];