How to change the background color of MFMailComposeViewController? I tried to add
mailController.view.backgroundColor = [UIColor redColor];
but the color is still white. Please help.
How to change the background color of MFMailComposeViewController? I tried to add
mailController.view.backgroundColor = [UIColor redColor];
but the color is still white. Please help.
I started debugging the MFMailComposeViewController
hierarchy. Heres my code.
MFMailComposeViewController *mailComposeViewController = [[MFMailComposeViewController alloc] init];
[self presentViewController:mailComposeViewController animated:YES completion:^{
UIViewController* mailViewController = [mailComposeViewController.topViewController.childViewControllers firstObject];
UIView *mailView = [mailViewController.view.subviews firstObject];
CALayer *mailLayer = mailView.layer;
mailLayer.opacity = 0.5f;
UIView *backgroundView = [[UIView alloc] initWithFrame:mailView.bounds];
backgroundView.backgroundColor = [UIColor redColor];
[mailViewController.view insertSubview:backgroundView atIndex:0];
}];
What I found is that the MFMailComposeViewController
which is a kind of UINavigationController
has a top view controller which has a child view controller. The child view controller's view has a subview. This subview is where the content exists.
The issue is there are no subviews to this view. So I looked to see if it's layer has sublayers. It does not. By changing the layers alpha and adding a view with a background color behind this view we can clearly see this view is indeed the view we want.
After some searching around I found out that the mailLayer
, which is a CALayerHost
, can not only display contents from another process; it also allows user interaction to pass from the host app to the remote process. In other words, this class is the key to transmitting both user actions and graphics across process boundaries.
So I think this is a dead end. You won't be able to elegantly change the background color.