在iOS13之前,我使用下面的代码删除了标签栏的顶部边框:
UITabBar.appearance().shadowImage = UIImage()
UITabBar.appearance().backgroundImage = UIImage()
但是它不适用于iOS13,我正在寻找解决方案。你有什么想法吗?
答案 0 :(得分:8)
快速4 +:
在您的TabBarController类中编写以下代码:
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()
}
要进行标题调整,请使用此:
appearance.stackedLayoutAppearance.normal.titlePositionAdjustment = UIOffset(horizontal: 0, vertical: -12)
对于目标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];
}
答案 1 :(得分:1)
在iOS 13中,您可以使用基于外观的方法以及用于配置透明度的内置方法:
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
}
要再次将其更改,可以使用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
}