'Custom Navbar and segmented control swiftui
I have some trouble with custom navbar. Before i use Segmented control it worked fine, but now with segmented control the color and font of the navbar doesn't update. I'm using Init() to customize both. Here my code:
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)
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
