xcode 使用自定义图层时移除选项卡栏背景

zte4gxcn  于 2023-03-24  发布在  其他
关注(0)|答案(2)|浏览(146)

我已经成功地创建了一个自定义的圆形浮动标签栏,但我如何删除默认的标签栏(如图中箭头所示)。我试图将标签栏背景设置为UIImage()并将背景颜色设置为Clear,但仍然不起作用。我的代码:

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)
bvpmtnay

bvpmtnay1#

使用选项卡栏外观:

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

4nkexdtk2#

所有iOS版本

self.tabBar.backgroundColor = UIColor.white
self.tabBar.isTranslucent = false

// set a specific tab bar color
if #available(iOS 13.0, *) {
    let tabBarAppearance = UITabBarAppearance()
    tabBarAppearance.configureWithOpaqueBackground()
    tabBarAppearance.backgroundEffect = .none
    tabBarAppearance.shadowColor = .clear
    tabBarAppearance.backgroundColor = UIColor.white
    UITabBar.appearance().standardAppearance = tabBarAppearance
    if #available(iOS 15.0, *) {
        UITabBar.appearance().scrollEdgeAppearance = tabBarAppearance
    }
}

相关问题