UITabBar相关

222 阅读1分钟
let titleTextAttributes = [
            NSAttributedString.Key.foregroundColor: normalColor,
            NSAttributedString.Key.font: Font(10, .medium)]
let selectedTitleTextAttributes = [
            NSAttributedString.Key.foregroundColor: selectedColor,
            NSAttributedString.Key.font: Font(10,.medium)]
            
if #available(iOS 13.0, *) {
            ///tabbar文字颜色
            let itemAppearance = UITabBarItemAppearance()
            itemAppearance.normal.titleTextAttributes = titleTextAttributes
            itemAppearance.selected.titleTextAttributes = selectedTitleTextAttributes
            let tabbarApperance = UITabBarAppearance()
            tabbarApperance.stackedLayoutAppearance = itemAppearance
            ///tabbar背景颜色
            tabbarApperance.backgroundImage = UIImage(color: barBackgroundColor)
            ///tabbar顶部横线颜色
            tabbarApperance.shadowImage = UIImage(color: barLineColor)
            tabBar.standardAppearance = tabbarApperance
            if #available(iOS 15.0, *) {
                tabBar.scrollEdgeAppearance = tabbarApperance
            }
} else {
            ///tabbar文字颜色
            UITabBarItem.appearance().setTitleTextAttributes(titleTextAttributes, for: .normal)
            UITabBarItem.appearance().setTitleTextAttributes(selectedTitleTextAttributes, for: .selected)
            ///tabbar背景颜色
            tabBar.backgroundImage = UIImage(color: barBackgroundColor)
            ///tabbar顶部横线颜色
            tabBar.shadowImage = UIImage(color: barLineColor)
}