如何改变MFMailComposeViewController的外观

huangapple go评论69阅读模式
英文:

How to change the appearance of MFMailComposeViewController

问题

以下是您要翻译的内容:

有没有办法影响MFMailComposeViewController的外观?

我有一个在按钮被点击时调用的函数。

@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)
    }
}

问题是它不太可读...
我可以看到用户自己输入的文本,但我只能猜测取消/发送按钮的位置。

我在这里找到了很多关于这个主题的帖子:
大多数都太旧了,不再起作用,其他一些根本不起作用。
我理解VC的外观应该由系统管理。我尝试将背景更改为黑色或白色,但这并没有改变任何事情。
我还发现很多修饰符(如.fileImporter)也有同样的问题。
所有这些UINavigationBar.appearance方法似乎也没有改变任何东西。
[iOS 15,iPhone]

欢迎任何建议!

英文:

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!

答案1

得分: 0

我发现在你的Assets.xcassets文件中更改AccentColor确实会影响这些叠加层的外观。
我将其改回为无,现在一切都看起来完美。

英文:

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.

huangapple
  • 本文由 发表于 2023年5月22日 22:07:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76307048.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定