Cordova iOS应用底部TabBar背景图在iOS11.x不显示问题求助
Hey, I’ve run into this exact issue before with Cordova apps on iOS 11+—the problem boils down to Apple changing how UITabBar renders background elements starting in iOS 11, which older Cordova versions (even 4.5.3) don’t fully account for. Let’s break down the fixes that worked for me:
Root Cause
iOS 11 completely revised the UITabBar view hierarchy. Previously, you could set a background image directly through Cordova’s preferences or basic native code, but iOS 11 introduced new background layers that override or hide custom images—especially if the tab bar is set to translucent (which is default in some Cordova versions).
Solutions
1. Manually Update Native Code (Most Reliable)
If you’re comfortable tweaking the iOS project directly, modify the CDVTabBarController class (or your custom tab bar controller) to force the background image to render correctly:
Open your Cordova iOS project in Xcode, find CDVTabBarController.m, and add this code to the viewDidLoad method:
- (void)viewDidLoad { [super viewDidLoad]; // Clear any existing background views that might block your image for (UIView *subview in self.tabBar.subviews) { if ([subview isKindOfClass:[UIImageView class]]) { [subview removeFromSuperview]; } } // Load your tab bar background image (make sure it's in Images.xcassets) UIImage *tabBarBackground = [UIImage imageNamed:@"your_tabbar_bg"]; UIImageView *backgroundView = [[UIImageView alloc] initWithImage:tabBarBackground]; backgroundView.frame = self.tabBar.bounds; // Insert the image at the bottom of the view hierarchy so it doesn't get covered [self.tabBar insertSubview:backgroundView atIndex:0]; // Disable translucency—this is critical for iOS 11+ self.tabBar.translucent = NO; }
- Replace
your_tabbar_bgwith the name of your image (without the file extension if it’s in Images.xcassets). - Ensure your image has 2x and 3x variants for different device resolutions.
2. Use a Cordova Plugin with iOS 11 Support
If you prefer not to edit native code, try using a plugin that’s updated for iOS 11+. For example:
- cordova-plugin-custom-config: Add these preferences to your
config.xml:<platform name="ios"> <preference name="TabBarBackgroundImage" value="tabbar_bg.png" /> <preference name="TabBarTranslucent" value="false" /> </platform> - If the plugin still doesn’t work, you may need to fork it and update its native code to match the approach in Solution 1.
3. Upgrade to a Newer Cordova iOS Platform
Cordova 4.5.3 is quite outdated—iOS 11 support was improved in Cordova iOS 5.x and later. Upgrade your platform with:
cordova platform remove ios cordova platform add ios@5.1.1 # Or the latest stable version
After upgrading, reinstall all your plugins and re-test. Newer Cordova versions have built-in fixes for iOS 11’s tab bar changes.
4. Verify Your Image Assets
Double-check these details to rule out simple resource issues:
- Your image is added to the iOS project’s target (in Xcode, select the image file and ensure the correct target is checked in the "File Inspector").
- You have properly sized variants (e.g.,
tabbar_bg.png,tabbar_bg@2x.png,tabbar_bg@3x.png). - The image path in your config or native code matches the actual file location.
Final Notes
Disabling tab bar translucency (translucent = NO) is the most common missing step—iOS 11’s translucent tab bar layers will obscure custom background images if not turned off.
内容的提问来源于stack exchange,提问作者Savanna

