我无法通过状态栏以白色显示时钟电池等。
我在堆栈溢出时读了很多类似的问题,但大多数都是旧的,不是用swift编写的。我能找到的最新答案建议override func prefferedStatusBarStyle
不再是一个功能。我尝试了以下方法,但它不起作用。
import Foundation
import UIKit
import MessageUI
class ContactUsViewController: MFMailComposeViewController {
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
override func loadView() {
super.loadView()
}
override func viewDidLoad() {
print("mail viewDidLoad()")
self.setNeedsStatusBarAppearanceUpdate()
}
}
我使用。
调用视图控制器if !MFMailComposeViewController.canSendMail() {
print("Mail services are not available")
return
}
self.timeSlider.removeFromSuperview()
let contactVC = ContactUsViewController()// MFMailComposeViewController()
contactVC.navigationBar.tintColor = UIColor.white
contactVC.mailComposeDelegate = self
// Configure the fields of the interface.
contactVC.setToRecipients(["support@example.com"])
contactVC.setSubject("Your subject here")
contactVC.setMessageBody("Enter message about bugs, problems, ideas how to make the app better etc.", isHTML: false)
contactVC.modalPresentationCapturesStatusBarAppearance = true
// Present the view controller
self.navigationController?.present(contactVC, animated: true, completion: nil)
视图控制器缺少哪些内容来更改其StatusBarStyle
?
答案 0 :(得分:1)
首先在应用信息列表中添加“查看基于控制器的状态栏外观”键,其值为NO
然后检查此代码
func showContactUs() {
if !MFMailComposeViewController.canSendMail() {
print("Mail services are not available")
return
}
let contactVC = ContactUsViewController()
//To make the nav bar stand out
//contactVC.navigationBar.barStyle = .blackTranslucent
contactVC.setToRecipients(["support@example.com"])
contactVC.setSubject("Your subject here")
contactVC.setMessageBody("Enter message about bugs, problems, ideas how to make the app better etc.", isHTML: false)
present(contactVC, animated: true)
}
class ContactUsViewController: MFMailComposeViewController {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
UIApplication.shared.statusBarStyle = .lightContent
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
UIApplication.shared.statusBarStyle = .default
}
}