我刚刚创建了UIStoryBoard的此扩展以更改navBar的属性,唯一的问题是,当我将此视图作为模式呈现时,样式没有改变,在ios 13之前一切都正确,
@objc extension UIStoryboard {
public func instantitiateChangingNavBar(viewControllerName: String) -> UIViewController {
let vc = self.instantiateViewController(withIdentifier: viewControllerName)
if #available(iOS 13.0, *) {
let barAppareance = UINavigationBarAppearance()
barAppareance.titleTextAttributes = [.foregroundColor: UIColor.white]
barAppareance.backgroundColor = UIColor.red
barAppareance.titleTextAttributes = [.font: UIFont(name: "Akrobat-ExtraBold", size: 18) as Any]
barAppareance.backButtonAppearance.normal.titleTextAttributes = [.font: UIFont(name: "Akrobat-ExtraBold", size: 18) as Any]
barAppareance.buttonAppearance.normal.titleTextAttributes = [.font: UIFont(name: "Akrobat-ExtraBold", size: 18) as Any]
barAppareance.doneButtonAppearance.normal.titleTextAttributes = [.font: UIFont(name: "Akrobat-ExtraBold", size: 18) as Any]
barAppareance.backButtonAppearance.highlighted.titleTextAttributes = [.font: UIFont(name: "Akrobat-ExtraBold", size: 18) as Any]
barAppareance.buttonAppearance.highlighted.titleTextAttributes = [.font: UIFont(name: "Akrobat-ExtraBold", size: 18) as Any]
barAppareance.doneButtonAppearance.highlighted.titleTextAttributes = [.font: UIFont(name: "Akrobat-ExtraBold", size: 18) as Any]
barAppareance.backButtonAppearance.disabled.titleTextAttributes = [.font: UIFont(name: "Akrobat-ExtraBold", size: 18) as Any]
barAppareance.buttonAppearance.disabled.titleTextAttributes = [.font: UIFont(name: "Akrobat-ExtraBold", size: 18) as Any]
barAppareance.doneButtonAppearance.disabled.titleTextAttributes = [.font: UIFont(name: "Akrobat-ExtraBold", size: 18) as Any]
barAppareance.backButtonAppearance.focused.titleTextAttributes = [.font: UIFont(name: "Akrobat-ExtraBold", size: 18) as Any]
barAppareance.buttonAppearance.focused.titleTextAttributes = [.font: UIFont(name: "Akrobat-ExtraBold", size: 18) as Any]
barAppareance.doneButtonAppearance.focused.titleTextAttributes = [.font: UIFont(name: "Akrobat-ExtraBold", size: 18) as Any]
vc.navigationController?.navigationBar.backgroundColor = UIColor.red
vc.navigationController?.navigationBar.barStyle = .default
vc.navigationController?.navigationBar.isTranslucent = false
vc.navigationController?.navigationBar.standardAppearance = barAppareance
vc.navigationController?.navigationBar.scrollEdgeAppearance = barAppareance
vc.navigationController?.navigationBar.compactAppearance = barAppareance
} else {
// Fallback on earlier versions
}
return vc
}
}