Tyler
Tyler

Reputation: 13

Custom Color for Nav Bar Button and StatusBar for UIActivityViewController

I have a UIAlertController with a style of ActionSheet. There are 2 options. When a user selects anyone of them, it displays Apple's built in UIActivityViewController. The problem I'm having is that when a user then selects the Message or Mail and others, the nav bar buttons are dark blue and the status bar is black. I want the buttons to be white and the status bar to be white. The only thing that works correctly is that the Nav Bar color is blue which I set in the app delegate.

The code I have in 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
}

When I present the UIActivityViewController, I'm able to customize the color of the "Cancel" button to a custom blue. But again, when the user presses the Message or any other options, it goes to a new screen and the colors are not correct. This is what I have:

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

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

 activityController.view.tintColor = primaryBlueColor

EDIT TO QUESTION 1:

I just found the answer for the buttons to change to the color white. Now all that is missing is the Status Bar to turn white. This is what I added to the App Delegate method above.

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

Any suggestions for the status bar?

Upvotes: 1

Views: 1483

Answers (2)

ZGski
ZGski

Reputation: 2538

In your AppDelegate, you can delete:

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

Next, add the following code to your ViewController:

extension UINavigationController {

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

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

Finally, go into your Info.plist and set:

View controller-based status bar appearance = YES

Upvotes: 1

user5483739
user5483739

Reputation:

To change the status bar to white, in swift, go to info.plist, and press the +and edit it like so:

enter image description here

Then, add this line to the AppDelegate.swift:

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

Upvotes: 0

Related Questions