SwiftUI将顶行添加到TabBar

时间:2019-11-19 16:30:17

标签: colors line swiftui tabbar

如何在TabBar的顶部添加行/分隔线以在视图和TabBar之间添加某种分隔线?

2 个答案:

答案 0 :(得分:0)

您可以更改TabBar线的颜色

init(){
  UITabBar.appearance().separatorColor = .red
  UITabBar.appearance().separatorInset = UIEdgeInsets(top: 0, left: -10, bottom: 0, right: 0)
}

答案 1 :(得分:0)

我忘记了我添加了使TabBar完全变为白色的代码。 但是我的阴影颜色是白色,所以我将其更改为灰色

extension UITabBarController {
override open func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    let appearance = UITabBarAppearance()
    appearance.configureWithOpaqueBackground()

    appearance.backgroundColor = .white
    appearance.shadowImage = UIImage()
    appearance.shadowColor = .gray

    appearance.stackedLayoutAppearance.normal.iconColor = .black
    appearance.stackedLayoutAppearance.normal.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.black]

    self.tabBar.standardAppearance = appearance
}

}