导航栏按钮的自定义颜色和 UIActivityViewController 的状态栏

Custom Color for Nav Bar Button and StatusBar for UIActivityViewController

我有一个带有 ActionSheet 样式的 UIAlertController。有2个选项。当用户选择其中任何一个时,它会显示 Apple 的内置 UIActivityViewController。我遇到的问题是,当用户随后选择“消息”或“邮件”等时,导航栏按钮是深蓝色,状态栏是黑色。 我希望按钮是白色,状态栏为白色。唯一能正常工作的是我在应用程序委托中设置的导航栏颜色是蓝色。

我在 App Delegate 中的代码:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

    // Nav Bar
    UINavigationBar.appearance().translucent = false
    UINavigationBar.appearance().opaque = true
    UINavigationBar.appearance().barTintColor = primaryBlueColor
    UINavigationBar.appearance().tintColor = UIColor.whiteColor()

    // Status Bar
    UIApplication.sharedApplication().statusBarHidden = false
    UIApplication.sharedApplication().statusBarStyle = UIStatusBarStyle.LightContent
}

当我显示 UIActivityViewController 时,我能够将 "Cancel" 按钮的颜色自定义为自定义蓝色。但是同样,当用户按下 Message 或任何其他选项时,它会转到一个新屏幕并且颜色不正确。这是我的:

 let activityController = UIActivityViewController(activityItems: [textFile], applicationActivities: nil)

 self.presentViewController(activityController, animated: true, completion: nil)

 activityController.view.tintColor = primaryBlueColor

编辑问题 1:

我刚刚找到了将按钮更改为白色的答案。现在所缺少的只是状态栏变为白色。这是我在上面的 App Delegate 方法中添加的内容。

 UIBarButtonItem.appearanceWhenContainedInInstancesOfClasses([UINavigationBar.classForCoder()]).tintColor = UIColor.whiteColor()

对状态栏有什么建议吗?

要将状态栏更改为白色,请在 swift 中转到 info.plist,然后按 + 并像这样编辑它:

然后,将此行添加到 AppDelegate.swift:

 // Changing the status bar's colour to white
 UIApplication.sharedApplication().statusBarStyle = .LightContent

在您的 AppDelegate 中,您可以删除:

    UIApplication.sharedApplication().statusBarHidden = true
    UIApplication.sharedApplication().statusBarStyle = UIStatusBarStyle.LightContent`

接下来,将以下代码添加到您的 ViewController:

extension UINavigationController {

   public override func preferredStatusBarStyle() -> UIStatusBarStyle {
       return .LightContent
   }

   public override func childViewControllerForStatusBarStyle() -> UIViewController? {
       return nil
   } 
}

最后,进入您的 Info.plist 并设置:

View controller-based status bar appearance = YES