【发布时间】:2022-11-03 20:32:18
【问题描述】:
我在运行 xcode 14 和 ios 16 时遇到了一些问题。
导航栏不变色,Tab Bar 与背景颜色相同(我认为应该有不同的色调)。
class MainTabController: UITabBarController {
// MARK: - Properties
// MARK: - Lifecycle
override func viewDidLoad() {
super.viewDidLoad()
configureViewControllers()
}
// MARK: - Helpers
func configureViewControllers() {
let feed = FeedController()
let nav1 = templateNavigationController(image: UIImage(named: "home_unselected"), rootViewController: feed)
let explore = ExploreController()
let nav2 = templateNavigationController(image: UIImage(named: "search_unselected"), rootViewController: explore)
let notifications = NotificationsController()
let nav3 = templateNavigationController(image: UIImage(named: "search_unselected"), rootViewController: notifications)
let conversations = ConversationsController()
let nav4 = templateNavigationController(image: UIImage(named: "search_unselected"), rootViewController: conversations)
viewControllers = [nav1, nav2, nav3, nav4]
}
func templateNavigationController(image: UIImage?, rootViewController: UIViewController) -> UINavigationController {
let nav = UINavigationController(rootViewController: rootViewController)
nav.tabBarItem.image = image
nav.navigationBar.barTintColor = .white
return nav
}
}
我试过设置导航栏的外观:
let appearance = UINavigationBarAppearance()
appearance.configureWithOpaqueBackground()
appearance.backgroundColor = .white
nav.navigationBar.standardAppearance = appearance
nav.navigationBar.scrollEdgeAppearance = nav.navigationBar.standardAppearance
这似乎有点多余,您是否必须每次为每个导航控制器都这样做?
【问题讨论】:
标签: ios swift uinavigationcontroller uikit uitabbarcontroller