[英]Can't set tab bar shadow image in iOS 13
Before iOS13, I used the code below to remove the tab bar top border:在 iOS13 之前,我使用下面的代码来移除标签栏上边框:
UITabBar.appearance().shadowImage = UIImage()
UITabBar.appearance().backgroundImage = UIImage()
But it does not work with iOS13, and I am looking for a solution to this.但它不适用于 iOS13,我正在寻找解决方案。 Do you have any thoughts?
你有什么想法吗?
Swift 4+: Swift 4+:
In your TabBarController class write this:在您的 TabBarController class 中写下:
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用于物镜 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:在 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
}
And to change it back again, you can do the same using configureWithDefaultBackground():要再次更改它,您可以使用 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
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.