Before iOS13, I used the code below to remove the tab bar top border:
UITabBar.appearance().shadowImage = UIImage()
UITabBar.appearance().backgroundImage = UIImage()
But it does not work with iOS13, and I am looking for a solution to this. Do you have any thoughts?
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With