在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)
sah*_*ain 29
只有2行删除了背线
let appearance = tabBar.standardAppearance
appearance.shadowImage = nil
appearance.shadowColor = nil
tabBar.standardAppearance = appearance;
Run Code Online (Sandbox Code Playgroud)
在 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)
从 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)
这对我有用@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)