skip to Main Content

enter image description here

I have created a custom rounded floating tab bar successfully but how can i removed the default tabbar (shown with arrow in the picture). I tried to set tabbar background to UIImage() and set background color to clear but it is still not working.
My code:

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)

2

Answers


  1. Use the tab bar appearance:

            let app = UITabBarAppearance()
            app.backgroundEffect = .none
            app.shadowColor = .clear
            tabBar.standardAppearance = app
    
    Login or Signup to reply.
  2. For All iOS Versions

    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
        }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search