从TabBar中删除第一行

jca*_*cho 15 tabbar ios ios10

在iOS 10上,此代码无法删除tabBar阴影线:

[[UITabBar appearance] setShadowImage:[[UIImage alloc] init]];
Run Code Online (Sandbox Code Playgroud)

有人知道,我该怎么做才能删除它?

iOS 9.3这两行中删除该行,但iOS 10忽略setShadowImage命令.

Mit*_*iya 35

试着低估iOS 10的代码: -

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    [[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:@"fondoTabBar"]];
    [UITabBar appearance].layer.borderWidth = 0.0f;
    [UITabBar appearance].clipsToBounds = true;
    return YES;
}
Run Code Online (Sandbox Code Playgroud)

Swift 3.x

UITabBar.appearance().layer.borderWidth = 0.0
UITabBar.appearance().clipsToBounds = true
Run Code Online (Sandbox Code Playgroud)

  • 感谢印度开发人员社区,这不是第一次帮助我解决堆栈溢出的iOs问题,非常感谢你! (2认同)

sah*_*ain 29

只有2行删除了背线

let appearance = tabBar.standardAppearance
appearance.shadowImage = nil
appearance.shadowColor = nil
tabBar.standardAppearance = appearance;
Run Code Online (Sandbox Code Playgroud)

  • 在iOS13上不再可用!有人尝试过吗?有一个新的`tabBar.standardAppearance.shadowImage`,但是根本不起作用... (2认同)
  • @SoftDesigner Yep无法在iOS 13中使用。 (2认同)
  • @SoftDesigner我有同样的问题,您找到适用于iOS 13的任何解决方案吗? (2认同)

den*_*lor 8

在 iOS 14 上测试

override func viewDidLoad() {
    // Remove default border line
    tabBar.shadowImage = UIImage()
    tabBar.backgroundImage = UIImage()
    tabBar.backgroundColor = UIColor.white
}
Run Code Online (Sandbox Code Playgroud)


小智 8

对于iOS 13

if (@available(iOS 13.0, *)) {
    UITabBarAppearance *appearance = [self.tabBarController.tabBar.standardAppearance copy];
    appearance.shadowImage = nil;
    appearance.shadowColor = nil;
    self.tabBarController.tabBar.standardAppearance = appearance;
}
Run Code Online (Sandbox Code Playgroud)


mkz*_*mkz 7

从 iOS 13.3 开始的工作解决方案

// remove top line
if #available(iOS 13.0, *) {
    // ios 13.0 and above
    let appearance = tabBar.standardAppearance
    appearance.shadowImage = nil
    appearance.shadowColor = nil
    appearance.backgroundEffect = nil
    // need to set background because it is black in standardAppearance
    appearance.backgroundColor = .someColor
    tabBar.standardAppearance = appearance
} else {
    // below ios 13.0
    let image = UIImage()
    tabBar.shadowImage = image
    tabBar.backgroundImage = image
    // background
    tabBar.backgroundColor = .someColor
}
Run Code Online (Sandbox Code Playgroud)


kir*_*net 5

这对我有用@iso13:

AppDelegate.swift

UITabBar.appearance().clipsToBounds = true
UITabBar.appearance().shadowImage = nil
Run Code Online (Sandbox Code Playgroud)

或者

UITabBar.appearance().clipsToBounds = true
UITabBar.appearance().layer.borderWidth = 0
Run Code Online (Sandbox Code Playgroud)

或者

UITabBar.appearance().clipsToBounds = true
UITabBar.appearance().layer.borderColor = UIColor.clear.cgColor
Run Code Online (Sandbox Code Playgroud)