iOS 13 大型导航栏外观 + Tabbar 图像
Posted
技术标签:
【中文标题】iOS 13 大型导航栏外观 + Tabbar 图像【英文标题】:iOS 13 Large Navigation bar appearance + Tabbar images 【发布时间】:2019-07-18 13:11:32 【问题描述】:我在 ios 13 模拟器和标签栏图像中有导航栏的有线 UI
12.1 的屏幕截图
我使用了以下设置
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
我不要半透明导航栏
任何帮助或建议将不胜感激
提前致谢
【问题讨论】:
第二张图片是你预期的navigationBar和tabbar吗? @Vicky_Vignesh 是的,这是运行良好的 ios12 的屏幕截图。第一个屏幕截图是 ios13,它在顶部显示黑条 你好。同样的问题,你找到解决办法了吗? @PrashantTukadiya 我刚刚发现如何在 iOS 13 中自定义导航栏,只需使用 UINavigationBarAppearance。 @mahan 正在开发中 【参考方案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
希望这会有所帮助。
【讨论】:
以上是关于iOS 13 大型导航栏外观 + Tabbar 图像的主要内容,如果未能解决你的问题,请参考以下文章