Change status bar colours in MFMailComposeViewController through UIActivityViewController
Asked Answered
K

4

11

I am trying to change the colour of the navigation bar buttons, navigation bar tint colour and text colour, however I don't seem to be getting anywhere. The MFMailComposeViewController is being activated via a UIActivityViewController and I have tried a few different methods that have worked before (not through a UIActivityViewController though).

This is my current code:

    UINavigationBar.my_appearanceWhenContainedIn(MFMailComposeViewController).barTintColor = UIColor.blackColor()

This was suggested here. I have also tried this:

    activityVC.navigationController?.navigationBar.tintColor = UIColorFromRGB(0x0096FF)
    activityVC.navigationController?.navigationBar.barTintColor = UIColor.whiteColor()

I'm also looking to change the status bar colour.

Anyone have any ideas?

UPDATE:

I fixed the navigation bar issues for the buttons and title, but still looking for a solution to the status bar. Doing this doesn't work:

    self.presentViewController(activityVC, animated: true, completion: { () in
        UIApplication.sharedApplication().setStatusBarStyle(UIStatusBarStyle.LightContent, animated: true)
    })
Kline answered 11/8, 2015 at 19:19 Comment(0)
C
4

You can subclass the MFMailViewController and override its viewWillAppear method

override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)
    UIApplication.sharedApplication().statusBarStyle = UIStatusBarStyle.LightContent
    self.navigationController.navigationBar.translucent = false
    self.navigationController.navigationBar.opaque = false
    self.navigationController.navigationBar.barTintColor = UIColor.blueColor()
}

Since you only want the status bar to be lightcontentwhen the MFMailComposeViewController is active, you shouldn't put the

UIApplication.sharedApplication().statusBarStyle = UIStatusBarStyle.LightContent

into your app delegates didFinishLoading. This would set it lightContent for your whole application.

Consternation answered 1/9, 2015 at 7:24 Comment(1)
can you mark this as correct answer if it solved your problem please?Consternation
L
1

for iOS8 you use barTintColor to change the color of status

    NSString *invitationText = @"test";
   [UINavigationBar appearance].barTintColor = [UIColor whiteColor];
   MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
   mc.mailComposeDelegate = self;
   [mc setSubject:@"Test "];
   [mc setMessageBody:invitationText isHTML:YES];
   [self presentViewController:mc animated:YES completion:NULL];
Likeminded answered 1/9, 2015 at 7:23 Comment(0)
B
0

Go to your app delegate file and add these lines to your didFinishLaunchingWithOptions :) It will update the status bar color for all view controllers.

UIApplication.sharedApplication().statusBarStyle = UIStatusBarStyle.LightContent

Additionally in your info.plist file add a new key called "View controller-based status bar appearance" and set the value to "NO"

UPDATE

To set diffrent styles between views try this:

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

Then you can return light or dark depending on what you are trying to achieve :)

Betseybetsy answered 29/8, 2015 at 22:57 Comment(1)
I have this, but I need the status bar style to be different between view controllers.Kline
C
-2

MFMailComposeViewController sets its own Status-Bar style, which you don't have access to. You can probably dig into some private APIs to do this, but then your app definitely will be rejected by Apple.

As a side note though, you shouldn't be changing anything about Apple provided UIViewController(s). They look that way because they're styled after the original app. It's meant to give users a sense of location and direction in an app. Apple may reject your app, too, because you've changed their stuff.

Cenogenesis answered 1/9, 2015 at 2:54 Comment(1)
While that may be the case, I've had many other apps approved that do exactly the same thing so I'm not too worried about it being rejected.Kline

© 2022 - 2024 — McMap. All rights reserved.