iOS13之前,我使用下面的代码来移除选项卡顶部边框:
UITabBar.appearance().shadowImage = UIImage()
UITabBar.appearance().backgroundImage = UIImage()
但是它不适用于iOS13,我正在寻找解决方案。你有什么想法吗?
Swift 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)
针对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];
}
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
}