在iOS 13中设置View Controller不会更改导航栏样式

时间:2019-09-24 08:05:37

标签: ios swift uistoryboard ios13

我刚刚创建了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
    }

}

0 个答案:

没有答案