Can't set tab bar shadow image in iOS 13
Swift 4+:
In your TabBarController class write this:
if #available(iOS 13, *) {
let appearance = self.tabBar.standardAppearance.copy()
appearance.backgroundImage = UIImage()
appearance.shadowImage = UIImage()
appearance.shadowColor = .clear
self.tabBar.standardAppearance = appearance
} else {
self.tabBar.shadowImage = UIImage()
self.tabBar.backgroundImage = UIImage()
}
For title adjustment use this:
appearance.stackedLayoutAppearance.normal.titlePositionAdjustment = UIOffset(horizontal: 0, vertical: -12)
For Objective C
if (@available(iOS 13.0, *)) {
UITabBarAppearance* appearance = self.tabBar.standardAppearance.copy;
appearance.backgroundImage = [UIImage new];
appearance.shadowImage = [UIImage new];
appearance.shadowColor = [UIColor clearColor];
// Title adjustment
appearance.stackedLayoutAppearance.normal.titlePositionAdjustment = UIOffsetMake(0, -12);
self.tabBar.standardAppearance = appearance;
} else {
self.tabBar.shadowImage = [UIImage new];
self.tabBar.backgroundImage = [UIImage new];
}
In iOS 13 you can use an appearance based approach with built in methods for configuring transparency:
if #available(iOS 13, *) {
let appearance = self.tabBar.standardAppearance.copy()
appearance.configureWithTransparentBackground()
tabBar.standardAppearance = appearance
} else {
tabBar.backgroundImage = UIImage()
tabBar.shadowImage = UIImage()
tabBar.barTintColor = UIColor.clear
}
And to change it back again, you can do the same using configureWithDefaultBackground():
if #available(iOS 13, *) {
let appearance = self.tabBar.standardAppearance.copy()
appearance.configureWithDefaultBackground()
tabBar.standardAppearance = appearance
} else {
tabBar.barTintColor = nil
tabBar.backgroundImage = nil
tabBar.shadowImage = nil
}