Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change status bar colours in MFMailComposeViewController through UIActivityViewController

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)
    })
like image 625
user3746428 Avatar asked Aug 11 '15 19:08

user3746428


2 Answers

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.

like image 167
MarkHim Avatar answered Nov 13 '22 19:11

MarkHim


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];
like image 1
amit gupta Avatar answered Nov 13 '22 20:11

amit gupta