Awe*_*ple 10 border line uitabbar ios
我一直在应用程序中使用UITabbar.UITabbar顶部有一条上边界线.参考下图: -
我用Google搜索并尝试了以下建议的代码: -
[[UITabBar appearance] setShadowImage:[[UIImage alloc] init]];
Run Code Online (Sandbox Code Playgroud)
也
[[UITabBar appearance] setShadowImage:nil];
self.navigationController.toolbar.clipsToBounds = YES;
Run Code Online (Sandbox Code Playgroud)
但他们都没有工作.有解决方案吗
Bar*_*mre 12
适用于iOS 13 和 Swift 5 的解决方案:
/**
* A custom subclass of `UITabBarController` to use whenever you want
* to hide the upper border of the `UITabBar`.
*/
class TabBarController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
tabBar.backgroundColor = UIColor.white
// Removing the upper border of the UITabBar.
//
// Note: Don't use `tabBar.clipsToBounds = true` if you want
// to add a custom shadow to the `tabBar`!
//
if #available(iOS 13, *) {
// iOS 13:
let appearance = tabBar.standardAppearance
appearance.configureWithOpaqueBackground()
appearance.shadowImage = nil
appearance.shadowColor = nil
tabBar.standardAppearance = appearance
} else {
// iOS 12 and below:
tabBar.shadowImage = UIImage()
tabBar.backgroundImage = UIImage()
}
}
}
Run Code Online (Sandbox Code Playgroud)
小智 8
[self.tabBar setValue:@(YES) forKeyPath:@"_hidesShadow"];
Run Code Online (Sandbox Code Playgroud)
或者你可以使用
[[UITabBar appearance] setShadowImage:[UIImage imageNamed:@"transparentShadow.png"]];
Run Code Online (Sandbox Code Playgroud)
要么
[[UITabBar appearance] setShadowImage:nil];
Run Code Online (Sandbox Code Playgroud)
这对我来说适用于 iOS 11、XCode 9.4
UITabBar.appearance().shadowImage = UIImage()
UITabBar.appearance().backgroundImage = UIImage()
UITabBar.appearance().backgroundColor = UIColor.white
Run Code Online (Sandbox Code Playgroud)
小智 5
Swift 5 对我有用
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
myTabBar.clipsToBounds = true
}
Run Code Online (Sandbox Code Playgroud)