iOS 13大导航栏+ Tabbar图像

时间:2019-07-18 13:11:32

标签: swift uitabbar navigationbar ios13

我在iOS 13模拟器和标签栏图像中具有用于导航栏的有线UI

enter image description here

12.1的ScreenShot

enter image description here

我使用了以下设置

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))

}

对于标签栏

    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

我不希望半透明导航栏

任何帮助或建议将不胜感激

预先感谢

1 个答案:

答案 0 :(得分:1)

这是我通过iOS 13支持自定义导航栏的方式:

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

希望这会有所帮助。