美文网首页
ios15 以上系统导航栏设置样色无效

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

作者: Albert新荣 | 来源:发表于2021-10-21 17:12 被阅读0次

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]
        }

相关文章

网友评论

      本文标题:ios15 以上系统导航栏设置样色无效

      本文链接:https://www.haomeiwen.com/subject/ukafaltx.html