如何在 iOS 14 中自定义 MFMailComposeViewController

How to customize MFMailComposeViewController in iOS 14

我想在我的应用程序中自定义 MFMailComposeViewController 样式及其行为,但我的所有尝试都失败了。我尝试了几种方法: 第一种方式:

let mailComposeViewController = MFMailComposeViewController()
...
UINavigationBar.appearance().tintColor = UIColor.red //don't see changes
UINavigationBar.appearance().barTintColor = UIColor.green //don't see changes
UINavigationBar.appearance().backgroundColor = UIColor.yellow //don't see changes
UINavigationBar.appearance().isTranslucent = false //don't see changes
UINavigationBar.appearance().clipsToBounds = false //don't see changes
UINavigationBar.appearance().prefersLargeTitles = false //don't see changes

present(mailComposeViewController, animated: true, completion: nil)

第二种方式:

extension MFMailComposeViewController {
    open override func viewDidLoad() {
        super.viewDidLoad()
        self.navigationBar.clipsToBounds = true //don't see changes
        self.navigationBar.prefersLargeTitles = false //don't see changes
        self.navigationBar.isTranslucent = false //don't see changes
        self.navigationBar.barTintColor = UIColor.green //don't see changes
        self.navigationBar.tintColor = UIColor.red //only this works!
    }
}

PS 我最感兴趣的是将 prefersLargeTitles 更改为 false 或像此处那样更改 navigationBarStyle :

我的结果:

来自苹果:

Important You must not modify the view hierarchy presented by this view controller. However, you can customize the appearance of the interface using the UIAppearance protocol.

我认为 Apple 不认可您的第二种方式的代码,您不应该修改此视图。但是,尝试:

UINavigationBar.appearance().tintColor = UIColor.red 
UINavigationBar.appearance().barTintColor = UIColor.green 
UINavigationBar.appearance().backgroundColor = UIColor.yellow 
UINavigationBar.appearance().isTranslucent = false 
UINavigationBar.appearance().clipsToBounds = false 
UINavigationBar.appearance().prefersLargeTitles = false 

let mailComposeViewController = MFMailComposeViewController()
present(mailComposeViewController, animated: true, completion: nil)