无法在iOS 13中设置标签栏阴影图像

Vol*_*nko 3 iphone ios swift ios13

在iOS13之前,我使用下面的代码删除了标签栏的顶部边框:

UITabBar.appearance().shadowImage = UIImage()
UITabBar.appearance().backgroundImage = UIImage()
Run Code Online (Sandbox Code Playgroud)

但这不适用于iOS13,我正在寻找解决方案。你有什么想法吗?

Sar*_*yan 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()
    }
Run Code Online (Sandbox Code Playgroud)

对于标题调整,请使用以下命令:

appearance.stackedLayoutAppearance.normal.titlePositionAdjustment = UIOffset(horizontal: 0, vertical: -12)
Run Code Online (Sandbox Code Playgroud)

对于目标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];
}
Run Code Online (Sandbox Code Playgroud)

  • @dharam您可以从UItabbaritem获取标准外观的副本,然后将其更改为外观。stackedLayoutAppearance.normal.titleTextAttributes =“您的属性” (2认同)