【问题标题】:Remove tab bar background when using custom layer使用自定义图层时删除标签栏背景
【发布时间】:2021-09-30 05:44:01
【问题描述】:

我已经成功创建了一个自定义的圆形浮动标签栏,但是我怎样才能删除默认的标签栏(如图中的箭头所示)。我尝试将标签栏背景设置为 UIImage() 并将背景颜色设置为清除,但它仍然无法正常工作。 我的代码:

let layer = CAShapeLayer()
    guard let tabBar = tabBarController?.tabBar else {return}
    layer.path = UIBezierPath(roundedRect: CGRect(x: 30,
                                                  y: tabBar.bounds.minY + 5,
                                                  //y: tabBar.bounds.minY - 28,
                                                  width: tabBar.bounds.width - 60,
                                                  height: tabBar.bounds.height - 24),
                              cornerRadius: (tabBar.frame.width / 2)).cgPath
    layer.shadowColor = UIColor.lightGray.cgColor
    layer.shadowOffset = CGSize(width: 5.0, height: 5.0)
    layer.shadowRadius = 25.0
    layer.shadowOpacity = 0.3
    layer.borderWidth = 1.0
    layer.opacity = 1.0
    layer.masksToBounds = false
    layer.fillColor = UIColor.white.cgColor
    
    tabBar.layer.insertSublayer(layer, at: 0)

【问题讨论】:

  • 你有没有试过检查superviews是否有背景颜色?
  • @Aswath 是的,它们都没有背景颜色

标签: ios swift xcode uitabbar cashapelayer


【解决方案1】:

使用标签栏外观:

        let app = UITabBarAppearance()
        app.backgroundEffect = .none
        app.shadowColor = .clear
        tabBar.standardAppearance = app

【讨论】:

  • 试过这个解决方案还是不行
  • 为我工作,对不起。
  • 您是使用故事板还是以编程方式创建用户界面?
  • 我从故事板开始。但我看不出它会有什么不同。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-10-05
  • 2012-07-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多