Search code examples
swiftuitabbarnavigationbarios13

iOS 13 Large Navigation bar appearance + Tabbar images


I have wired UI for navigation bar in iOS 13 simulator and tabbar images

enter image description here

ScreenShot of 12.1

enter image description here

I have used following settings

func setupNavbarAndTabbar() {
    UINavigationBar.appearance().isOpaque = true
    UINavigationBar.appearance().isTranslucent = false
    UINavigationBar.appearance().barTintColor = UIColor(named: "PrimaryDark")
    UINavigationBar.appearance().tintColor = UIColor.white
    UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.font:Constants.AppTheme.Fonts.font(type: .FONT_BOLD, size: 19) ,NSAttributedString.Key.foregroundColor:UIColor.white]

    UINavigationBar.appearance().largeTitleTextAttributes   = [NSAttributedString.Key.font:Constants.AppTheme.Fonts.font(type: .FONT_BOLD, size: 34) ,NSAttributedString.Key.foregroundColor:UIColor.white]



    UITabBar.appearance().tintColor = .white
    UITabBar.appearance().barTintColor = UIColor(named: "PrimaryDark")
    UITabBar.appearance().isOpaque = true
 //   UITabBar.appearance().isTranslucent = false


    UITabBar.appearance().backgroundImage = UIImage.init(color: UIColor(named: "PrimaryDark")!, size: CGSize(width: 1, height: 1))

    //Set Shadow Color
 //   UITabBar.appearance().shadowImage = UIImage.init(color: UIColor.init(red: 10/255.0, green: 14/255.0, blue: 19/255.0, alpha: 1.0), size: CGSize(width: 0, height: 0)) //UIImage.colorForNavBar(color: UIColor.init(red: 120/255.0, green: 120/255.0, blue: 120/255.0, alpha: 1.0))

}

For Tabbar

    tabBar.layer.shadowOffset = CGSize(width: 0, height: -1)
    tabBar.layer.shadowRadius = 2
    tabBar.layer.shadowColor = UIColor.init(red: 10/255.0, green: 14/255.0, blue: 19/255.0, alpha: 1.0).cgColor
    tabBar.layer.shadowOpacity = 0.3

I don't want translucent navigation bar

Any Help or suggestion would be appreciated

Thanks in advance


Solution

  • This is how I customize the navigation bar with iOS 13 support:

    extension UINavigationBar
    {
        class func setupAppearance()
        {
            let textAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
            if #available(iOS 13.0, *)
            {
                let appearance = UINavigationBarAppearance()
                appearance.backgroundColor = .darkGray
                appearance.titleTextAttributes = textAttributes
                appearance.largeTitleTextAttributes = textAttributes
    
                self.appearance().standardAppearance = appearance
                self.appearance().compactAppearance = appearance
                self.appearance().scrollEdgeAppearance = appearance
                self.appearance().tintColor = .white
                self.appearance().prefersLargeTitles = true
            }
            else
            {
                self.appearance().isTranslucent = false
                self.appearance().barTintColor = .darkGray
                self.appearance().tintColor = .white
                self.appearance().barStyle = .black
    
                self.appearance().titleTextAttributes = textAttributes
                if #available(iOS 11.0, *)
                {
                    self.appearance().largeTitleTextAttributes = textAttributes
                    self.appearance().prefersLargeTitles = true
                }
            }
        }
    }
    

    Hope this helps.