Search code examples
swiftoverlaymfmailcomposeviewcontroller

How to change the appearance of MFMailComposeViewController


Is there any way to influence the appearance of the MFMailComposeViewController?

I have a function that is called when a button is tapped.

    @objc private func presentMailComposer() {
    ActionHandler.shared.shareMail()
    guard MFMailComposeViewController.canSendMail() else { /* TODO: error output to user */ return }

    let mailComposer = MFMailComposeViewController()
    mailComposer.mailComposeDelegate = self

    if let attachmentData = try? Data(contentsOf: pdfURL) {
        let fileName: String = self.pdfURL.lastPathComponent
        mailComposer.addAttachmentData(attachmentData, mimeType: "application/pdf" /* TODO: type needs to be changed for different document types */, fileName: fileName)
    }

    let allScenes = UIApplication.shared.connectedScenes
    let scene = allScenes.first { $0.activationState == .foregroundActive }
    if let windowScene = scene as? UIWindowScene {
        windowScene.keyWindow?.rootViewController?.present(mailComposer, animated: true, completion: nil)
    }
}

The problem is that it's not really readable... I can see the text the user types in by themself, but the cancel/send buttons I can only tap by guessing where they are.

I found a lot of posts here about the topic: Most of them are too old and don't work any longer and others don't work at all. I understand that the VC appearance should be managed by the system. I tried to change the background to black or white, but that didn't change anything. I also found that a lot of modifiers (like .fileImporter) have the same problem. All these UINavigationBar.appearance approaches don't seem to change anything either. [iOS 15, iPhone]

Every tip is welcome!


Solution

  • I found out that changing the AccentColor in your Assets.xcassets file does have an effect on the appearance of these overlays. I changed it back to none and everything looks perfect.