MFMailComposeViewController in iOS 7 statusbar are black
i have a feedback button in my ios 7 application with MFMailComposeViewController. After the user click this button the mailcomposer open but the statusbar changed to black. Have anybody a idea what can i do?
i have this problem only with ios7. i customizing my app for ios7.
MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init];
mailController.mailComposeDelegate = self;
[mailController setSubject:@"Feedback"];
// Fill out the email body tex
NSString *emailBody = [NSString stringWithFormat:@"testest"],
[UIDevice currentDevice].model,
[UIDevice currentDevice].systemVersion];
[mailController setMessageBody:emailBody isHTML:NO];
[mailController setToRecipients:[NSArray arrayWithObjects:@"[email protected]",nil]];
dispatch_async(dispatch_get_main_queue(), ^{
[self presentModalViewController:mailController animated:YES];
}
Solution 1:
Set the UIApplication statusBarStyle in the completion block of presentViewController for your MFMailComposeViewController. i.e.
MFMailComposeViewController *mailVC = [[MFMailComposeViewController alloc] init];
[self.navigationController presentViewController:mailVC animated:YES completion:^{
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}];
You may also need to add and/or set "View controller-based status bar appearance" to NO in your Info.plist file.
Solution 2:
Try to add category to MFMailComposeViewController
EDIT: this solution works if "View controller-based status bar appearance" == YES
@implementation MFMailComposeViewController (IOS7_StatusBarStyle)
-(UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleLightContent;
}
-(UIViewController *)childViewControllerForStatusBarStyle
{
return nil;
}
@end
Solution 3:
Swift solution.
Set View controller-based status bar appearance
to YES
import UIKit
import MessageUI
import AddressBookUI
extension MFMailComposeViewController {
override func preferredStatusBarStyle() -> UIStatusBarStyle {
return .LightContent
}
override func childViewControllerForStatusBarStyle() -> UIViewController? {
return nil
}
}
extension ABPeoplePickerNavigationController {
override func preferredStatusBarStyle() -> UIStatusBarStyle {
return .LightContent
}
override func childViewControllerForStatusBarStyle() -> UIViewController? {
return nil
}
}
Solution 4:
What did the trick for me was:
- Subclass MFMailComposeViewController
-
Override the two methods as described in answer 6
-(UIStatusBarStyle)preferredStatusBarStyle;
-(UIViewController *)childViewControllerForStatusBarStyle;
-
Override viewDidLoad as follows:
-(void)viewDidLoad {
[super viewDidLoad];
[self preferredStatusBarStyle];
[self setNeedsStatusBarAppearanceUpdate];
}
Solution 5:
Solution for Swift3
Add this to your ViewController:
extension MFMailComposeViewController {
open override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
open override var childViewControllerForStatusBarStyle: UIViewController? {
return nil
}
}
Set View controller-based status bar appearance
>> YES as below:
Thanks to @SoftDesigner
Another cleaner solution that may not change other settings in your app. While presenting the Mail VC change the status bar in the completion block:
controller.present(mailComposeViewController, animated: true) {
UIApplication.shared.statusBarStyle = .lightContent
}