在iOS 13中,他们更改了导航栏颜色的操作方式。现在,他们将UINavigationBarAppearance与UIBarButtonItemAppearance一起使用,以自定义导航栏以及standardAppearance和scrollEdgeAppearance。
我正在寻找一种使standardAppearance和scrollEdgeAppearance具有不同的导航栏颜色的方法。或更改每种外观的条形按钮图标颜色的功能。
//set the standard nav bar appearance
let navBarAppearance = UINavigationBarAppearance()
navBarAppearance.configureWithOpaqueBackground()
navBarAppearance.titleTextAttributes = [.foregroundColor: UIColor.white]
navBarAppearance.largeTitleTextAttributes = [.foregroundColor: UIColor.white]
navBarAppearance.backgroundColor = UIColor.mainAppColorForNavBar
//set bar button appearance
let buttonAppearance = UIBarButtonItemAppearance()
buttonAppearance.normal.titleTextAttributes = [.foregroundColor : UIColor.white]
navBarAppearance.buttonAppearance = buttonAppearance
UINavigationBar.appearance(whenContainedInInstancesOf: [UINavigationController.self]).standardAppearance = navBarAppearance
//set the scroll edge nav bar appearance
let scrollNavBarAppearance = UINavigationBarAppearance()
scrollNavBarAppearance.configureWithOpaqueBackground()
scrollNavBarAppearance.titleTextAttributes = [.foregroundColor: UIColor.label]
scrollNavBarAppearance.largeTitleTextAttributes = [.foregroundColor: UIColor.label]
//set bar button appearance
let scrollButtonAppearance = UIBarButtonItemAppearance()
scrollButtonAppearance.normal.titleTextAttributes = [.foregroundColor : UIColor.label]
scrollNavBarAppearance.buttonAppearance = scrollButtonAppearance
UINavigationBar.appearance(whenContainedInInstancesOf: [UINavigationController.self]).scrollEdgeAppearance = scrollNavBarAppearance
这将设置导航栏的颜色,但不会区分standardAppearance和scrollEdgeAppearance。
UINavigationBar.appearance().tintColor = UIColor.white
当前在scrollEdgeAppearance中(看起来像我想要的方式,不需要更改)
当前在standardAppearance中(按钮丢失,因为它与背景颜色相同,我想在standardAppearance中将图标颜色更改为白色)
感谢您的帮助。
谢谢