Search code examples
swiftuikituinavigationbaruitabbar

How to set navbar and tabbar not transparent and their borders visible


I can not find any info in internet about this question. I have tableview in UIViewcontroller and it is embedded in navigation controller. I want that my navbar was always like in scrolling state (borders are visible) and same thing with tabbar. Here is photo what I have(1-st) and what I want (2-nd).

enter image description here

enter image description here


Solution

  • In AppDelegate file in didFinishLaunchingWithOptions method added:

            //MARK: - NavBar appearance
            let navBarAppearance = UINavigationBarAppearance()
            navBarAppearance.backgroundColor = UIColor(named: "AccentColor")
            UINavigationBar.appearance().standardAppearance  = navBarAppearance
            UINavigationBar.appearance().scrollEdgeAppearance = navBarAppearance
            
            //MARK: - TabBar appearance
            let tabBarAppearance = UITabBarAppearance()
            tabBarAppearance.backgroundColor = UIColor(named: "AccentColor")
            UITabBar.appearance().standardAppearance  = tabBarAppearance
            UITabBar.appearance().scrollEdgeAppearance = tabBarAppearance