ios15 以上系统导航栏设置样色无效

2021-10-21  本文已影响0人  Albert新荣

SWIFT

     if #available(iOS 15.0, *){
            let appearance = UINavigationBarAppearance()
            appearance.configureWithOpaqueBackground()
            appearance.backgroundColor = UIColor.init(hex: "#302F32")
            appearance.titleTextAttributes = [NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 18), NSAttributedString.Key.foregroundColor: UIColor.white]
            self.navigationController?.navigationBar.standardAppearance = appearance
            self.navigationController?.navigationBar.scrollEdgeAppearance = self.navigationController?.navigationBar.standardAppearance
            
        }  else{
            self.navigationController?.navigationBar.setBackgroundImage(UIImage.init(color: UIColor.init(hex: "#302F32")), for: .default)
            self.navigationController?.navigationBar.isTranslucent = false
            let dict:NSDictionary = [NSAttributedString.Key.foregroundColor: UIColor.white,NSAttributedString.Key.font : UIFont.boldSystemFont(ofSize: 18)]
            self.navigationController?.navigationBar.titleTextAttributes = dict as? [NSAttributedString.Key : Any]
        }
上一篇 下一篇

猜你喜欢

热点阅读