更改 MFMailComposeViewController 上 send/cancel 按钮上的文本颜色
Changing color of text on send/cancel buttons on MFMailComposeViewController
我正在对应用程序进行最后润色并在物理设备上进行测试。就在我想越过终点线提交到 App Store 时,我遇到了颜色 MFMailComposeViewController's
send
和 cancel
按钮的问题。我在这里找到了很多答案,但 none 似乎让我过了终点线。
下面的方法可以发送电子邮件,但无论我做什么,send/cancel 按钮的颜色仍然是默认的蓝色。非常感谢任何纠正这种情况的建议。
谢谢!
@IBAction func sendFeedbackEmail(sender: AnyObject)
{
feedbackButton.pop()
print("sendFeedbackEmail called")
if MFMailComposeViewController.canSendMail()
{
let mailComposeViewController = configuredMailComposeViewController()
self.present(mailComposeViewController, animated: true, completion: nil)
} else {
self.showSendMailErrorAlert()
}
}
func configuredMailComposeViewController() -> MFMailComposeViewController
{
let mailComposerVC = MFMailComposeViewController()
mailComposerVC.mailComposeDelegate = self
mailComposerVC.navigationBar.tintColor = .red
mailComposerVC.navigationBar.isTranslucent = false
mailComposerVC.navigationBar.barTintColor = .white
mailComposerVC.setToRecipients(["testing@gmail.com"])
mailComposerVC.setSubject("Feedback")
return mailComposerVC
}
答案在这里。我希望,您没有将 baseViewController 用于 UIViewController。
@IBAction func sendFeedbackEmail(sender: AnyObject) {
feedbackButton.pop()
print("sendFeedbackEmail called")
if MFMailComposeViewController.canSendMail()
{
let mailComposeViewController = configuredMailComposeViewController()
mailComposeViewController.navigationBar.tintColor = UIColor.redColor()
self.presentViewController(mailComposeViewController, animated: true, completion: nil)
} else {
self.showSendMailErrorAlert()
}
}
Swift 4.0
mailComposeViewController.navigationBar.tintColor = UIColor.red
在 swift 4+ 中,新的 UI 样式带有发送按钮人字形,您只需在 modalPresentationStyle = .fullscreen 中显示 composerVC。然后它也会改变发送按钮的颜色。希望这有帮助。
let mailComposeVC = MFMailComposeViewController()
mailComposeVC.mailComposeDelegate = self
mailComposeVC.modalPresentationStyle = .fullScreen
mailComposeVC.navigationBar.tintColor = UIColor(red:131/255.0, green:184/255.0, blue:26/255.0, alpha:1)
self.present(mailComposeVC, animated: true, completion: nil)
我搜索了几个小时,一无所获。我只是随机尝试并得到了解决方案。我希望这可以帮助任何搜索此问题的人。
初始化前更改 UIButton 和条形按钮的颜色MFMailCOmposeViewController
并在关闭后重置颜色。
let navBtnColor = UIButton.appearance(whenContainedInInstancesOf: [UINavigationBar.self]).tintColor
let barBtnColor = UIBarButtonItem.appearance(whenContainedInInstancesOf: [UINavigationBar.self]).tintColor
let alerViewtColor = UIView.appearance().tintColor
let btnColor = UIButton.appearance().tintColor
let imageColor = UIImageView.appearance().tintColor
func reportAProblem() {
if MFMailComposeViewController.canSendMail() {UIBarButtonItem.appearance().setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.systemBlue], for: .normal)
UIButton.appearance().tintColor = UIColor.systemBlue
UIButton.appearance(whenContainedInInstancesOf: [UINavigationBar.self]).tintColor = UIColor.systemBlue
let mailComposerVC = MFMailComposeViewController()
mailComposerVC.mailComposeDelegate = self // Extremely important to set the --mailComposeDelegate-- property, NOT the --delegate-- property
var versionStr: String = ""
if let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String {
versionStr = version
}
mailComposerVC.setToRecipients(["support@idrive.com", "supportios@idrive.com"])
mailComposerVC.setSubject("IDrive Photos: \(feedbackTextView.text ?? "")")
let msg: String = String(format: "<html><body>\(feedbackTextView.text ?? "")<br/><br/><br/><br/><table> <tr><td>%@</td><td> : </td><td>%@</td></tr> <tr><td>%@</td><td> : </td><td>%@</td></tr> <tr><td>%@</td><td> : </td><td>%@</td></tr> <tr><td>%@</td><td> : </td><td>%@</td></tr> </table></body></html>", "Email Address".localized, (AppConfiguration.default.username)!, "Version".localized, versionStr, "iOS Version".localized, UIDevice.current.systemVersion, "Device".localized, UIDevice.current.modelName)
mailComposerVC.setMessageBody(msg, isHTML: true)
// attaching file
let documentURL = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
let destinationPath = URL.init(fileURLWithPath: documentURL + "/LogFile.txt")
if FileManager.default.fileExists(atPath: destinationPath.path) {
if let fileData = NSData(contentsOfFile: destinationPath.path) {
mailComposerVC.addAttachmentData(fileData as Data, mimeType: "text/html", fileName: "LogReport")
}
}
self.present(mailComposerVC, animated: true) {
UIView.appearance(whenContainedInInstancesOf: [UIAlertController.self]).tintColor = UIColor.systemBlue
}
} else {
}
}
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error _: Error?) {
UIButton.appearance(whenContainedInInstancesOf: [UINavigationBar.self]).tintColor = navBtnColor
UIBarButtonItem.appearance(whenContainedInInstancesOf: [UINavigationBar.self]).tintColor = barBtnColor
UIBarButtonItem.appearance().setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.white], for: .normal)
UIButton.appearance().tintColor = btnColor
UIView.appearance(whenContainedInInstancesOf: [UIAlertController.self]).tintColor = alerViewtColor
UIImageView.appearance().tintColor = imageColor
controller.dismiss(animated: true)
}
我正在对应用程序进行最后润色并在物理设备上进行测试。就在我想越过终点线提交到 App Store 时,我遇到了颜色 MFMailComposeViewController's
send
和 cancel
按钮的问题。我在这里找到了很多答案,但 none 似乎让我过了终点线。
下面的方法可以发送电子邮件,但无论我做什么,send/cancel 按钮的颜色仍然是默认的蓝色。非常感谢任何纠正这种情况的建议。
谢谢!
@IBAction func sendFeedbackEmail(sender: AnyObject)
{
feedbackButton.pop()
print("sendFeedbackEmail called")
if MFMailComposeViewController.canSendMail()
{
let mailComposeViewController = configuredMailComposeViewController()
self.present(mailComposeViewController, animated: true, completion: nil)
} else {
self.showSendMailErrorAlert()
}
}
func configuredMailComposeViewController() -> MFMailComposeViewController
{
let mailComposerVC = MFMailComposeViewController()
mailComposerVC.mailComposeDelegate = self
mailComposerVC.navigationBar.tintColor = .red
mailComposerVC.navigationBar.isTranslucent = false
mailComposerVC.navigationBar.barTintColor = .white
mailComposerVC.setToRecipients(["testing@gmail.com"])
mailComposerVC.setSubject("Feedback")
return mailComposerVC
}
答案在这里。我希望,您没有将 baseViewController 用于 UIViewController。
@IBAction func sendFeedbackEmail(sender: AnyObject) {
feedbackButton.pop()
print("sendFeedbackEmail called")
if MFMailComposeViewController.canSendMail()
{
let mailComposeViewController = configuredMailComposeViewController()
mailComposeViewController.navigationBar.tintColor = UIColor.redColor()
self.presentViewController(mailComposeViewController, animated: true, completion: nil)
} else {
self.showSendMailErrorAlert()
}
}
Swift 4.0
mailComposeViewController.navigationBar.tintColor = UIColor.red
在 swift 4+ 中,新的 UI 样式带有发送按钮人字形,您只需在 modalPresentationStyle = .fullscreen 中显示 composerVC。然后它也会改变发送按钮的颜色。希望这有帮助。
let mailComposeVC = MFMailComposeViewController()
mailComposeVC.mailComposeDelegate = self
mailComposeVC.modalPresentationStyle = .fullScreen
mailComposeVC.navigationBar.tintColor = UIColor(red:131/255.0, green:184/255.0, blue:26/255.0, alpha:1)
self.present(mailComposeVC, animated: true, completion: nil)
我搜索了几个小时,一无所获。我只是随机尝试并得到了解决方案。我希望这可以帮助任何搜索此问题的人。
初始化前更改 UIButton 和条形按钮的颜色MFMailCOmposeViewController
并在关闭后重置颜色。
let navBtnColor = UIButton.appearance(whenContainedInInstancesOf: [UINavigationBar.self]).tintColor
let barBtnColor = UIBarButtonItem.appearance(whenContainedInInstancesOf: [UINavigationBar.self]).tintColor
let alerViewtColor = UIView.appearance().tintColor
let btnColor = UIButton.appearance().tintColor
let imageColor = UIImageView.appearance().tintColor
func reportAProblem() {
if MFMailComposeViewController.canSendMail() {UIBarButtonItem.appearance().setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.systemBlue], for: .normal)
UIButton.appearance().tintColor = UIColor.systemBlue
UIButton.appearance(whenContainedInInstancesOf: [UINavigationBar.self]).tintColor = UIColor.systemBlue
let mailComposerVC = MFMailComposeViewController()
mailComposerVC.mailComposeDelegate = self // Extremely important to set the --mailComposeDelegate-- property, NOT the --delegate-- property
var versionStr: String = ""
if let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String {
versionStr = version
}
mailComposerVC.setToRecipients(["support@idrive.com", "supportios@idrive.com"])
mailComposerVC.setSubject("IDrive Photos: \(feedbackTextView.text ?? "")")
let msg: String = String(format: "<html><body>\(feedbackTextView.text ?? "")<br/><br/><br/><br/><table> <tr><td>%@</td><td> : </td><td>%@</td></tr> <tr><td>%@</td><td> : </td><td>%@</td></tr> <tr><td>%@</td><td> : </td><td>%@</td></tr> <tr><td>%@</td><td> : </td><td>%@</td></tr> </table></body></html>", "Email Address".localized, (AppConfiguration.default.username)!, "Version".localized, versionStr, "iOS Version".localized, UIDevice.current.systemVersion, "Device".localized, UIDevice.current.modelName)
mailComposerVC.setMessageBody(msg, isHTML: true)
// attaching file
let documentURL = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
let destinationPath = URL.init(fileURLWithPath: documentURL + "/LogFile.txt")
if FileManager.default.fileExists(atPath: destinationPath.path) {
if let fileData = NSData(contentsOfFile: destinationPath.path) {
mailComposerVC.addAttachmentData(fileData as Data, mimeType: "text/html", fileName: "LogReport")
}
}
self.present(mailComposerVC, animated: true) {
UIView.appearance(whenContainedInInstancesOf: [UIAlertController.self]).tintColor = UIColor.systemBlue
}
} else {
}
}
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error _: Error?) {
UIButton.appearance(whenContainedInInstancesOf: [UINavigationBar.self]).tintColor = navBtnColor
UIBarButtonItem.appearance(whenContainedInInstancesOf: [UINavigationBar.self]).tintColor = barBtnColor
UIBarButtonItem.appearance().setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.white], for: .normal)
UIButton.appearance().tintColor = btnColor
UIView.appearance(whenContainedInInstancesOf: [UIAlertController.self]).tintColor = alerViewtColor
UIImageView.appearance().tintColor = imageColor
controller.dismiss(animated: true)
}