在Xcode 11编译的tvOS 13应用中能否沿用tvOS9-12的UITabBarController默认UI?
Can a tvOS 13 app compiled with Xcode 11 use the UITabBarController default UI from tvOS 9-12?
Absolutely! tvOS 13 rolled out a fresh default design for UITabBarController, but you can easily revert to the classic tvOS 9-12 style using the UIBarAppearance APIs (introduced in tvOS 13, which Xcode 11 fully supports). Here's how to pull it off:
Option 1: Customize for a single UITabBarController
If you only want one tab bar controller to use the legacy style, add this code to its viewDidLoad() method:
override func viewDidLoad() { super.viewDidLoad() // Create an appearance that matches tvOS 9-12's tab bar look let legacyTabBarAppearance = UITabBarAppearance() // Set the dark, muted background typical of older tvOS versions legacyTabBarAppearance.backgroundColor = UIColor(red: 0.1, green: 0.1, blue: 0.1, alpha: 1.0) // Style selected items (white icon/text, red badge) legacyTabBarAppearance.stackedLayoutAppearance.selected.iconColor = .white legacyTabBarAppearance.stackedLayoutAppearance.selected.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white] legacyTabBarAppearance.stackedLayoutAppearance.selected.badgeBackgroundColor = .systemRed // Style unselected items (gray icon/text) legacyTabBarAppearance.stackedLayoutAppearance.normal.iconColor = .gray legacyTabBarAppearance.stackedLayoutAppearance.normal.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.gray] // Apply the style to both standard and scroll-edge states tabBar.standardAppearance = legacyTabBarAppearance tabBar.scrollEdgeAppearance = legacyTabBarAppearance }
Option 2: Apply the legacy style globally
To make every UITabBar in your app use the old design, set this up in your AppDelegate's launch method:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { if #available(tvOS 13.0, *) { let legacyTabBarAppearance = UITabBarAppearance() // Replicate the same appearance config as above legacyTabBarAppearance.backgroundColor = UIColor(red: 0.1, green: 0.1, blue: 0.1, alpha: 1.0) legacyTabBarAppearance.stackedLayoutAppearance.selected.iconColor = .white legacyTabBarAppearance.stackedLayoutAppearance.selected.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white] legacyTabBarAppearance.stackedLayoutAppearance.selected.badgeBackgroundColor = .systemRed legacyTabBarAppearance.stackedLayoutAppearance.normal.iconColor = .gray legacyTabBarAppearance.stackedLayoutAppearance.normal.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.gray] UITabBar.appearance().standardAppearance = legacyTabBarAppearance UITabBar.appearance().scrollEdgeAppearance = legacyTabBarAppearance } return true }
Quick Tips:
- The
UIBarAppearanceAPI is exclusive to tvOS 13+, which aligns perfectly with your target version, so no compatibility hiccups here. - Feel free to tweak the color values to match the exact shade of the old tvOS tab bar—adjust the
backgroundColorand text/icon colors to your liking. - Setting
scrollEdgeAppearanceensures the style stays consistent even when content scrolls beneath the tab bar.
内容的提问来源于stack exchange,提问作者Daniel Storm
相关产品推荐
相关产品推荐

