我在使用自定义导航栏时遇到了一些麻烦。在我使用分段控件之前它工作得很好,但现在使用分段控件,导航栏的颜色和字体不会更新。我正在使用 Init() 来自定义两者。这是我的代码:
init(){
UINavigationBar.appearance().isTranslucent = true
UINavigationBar.appearance().titleTextAttributes = [.font : UIFont(name: "Gilbert", size: 50)!, .foregroundColor: UIColor(named: "testo")!]
UINavigationBar.appearance().tintColor = UIColor(named: "color")
UISegmentedControl.appearance().selectedSegmentTintColor = UIColor(named: "testo")
UISegmentedControl.appearance().backgroundColor = .clear
//this will change the font size
UISegmentedControl.appearance().setTitleTextAttributes([.font : UIFont(name: "Gilbert", size: 30)!], for: .normal)
//these lines change the text color for various states
UISegmentedControl.appearance().setTitleTextAttributes([.foregroundColor : UIColor.white], for: .selected)
UISegmentedControl.appearance().setTitleTextAttributes([.foregroundColor : UIColor(named: "testo")!], for: .normal)
}