I need both cornerRadius and shadows in my tabBar. If I apply one, i can't get the other. To get cornerRadius, masksToBounds should be set to true, but this removes the shadowColor property of the tabBar.
From MyTabBarController.swift:
tabBar.layer.cornerRadius = 20
tabBar.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner]
tabBar.layer.masksToBounds = true
I tried adding a separate view in my TabBarController with the same frame and size as my TabBar and applied shadows to it. This did create shadows but an issue with that is when I navigate to another ViewController by presenting it fullscreen, the tabBar is hidden but the shadow view persists and covers the bottom of the screen.
TabBar UI requirement, shadow and cornerRadius
Issue with using a separate view for shadow, while a ViewController is presented full screen
From MyTabBarController.swift:
shadowView.frame = tabBar.frame
shadowView.backgroundColor = UIColor(named: "tabBarColor")
shadowView.layer.cornerRadius = 20
shadowView.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner]
shadowView.layer.masksToBounds = false
shadowView.layer.shadowColor = UIColor.black.withAlphaComponent(0.5).cgColor
shadowView.layer.shadowOffset = CGSize(width: -2, height: -4)
shadowView.layer.shadowOpacity = 0.5
shadowView.layer.shadowRadius = 20
view.addSubview(shadowView)
view.bringSubviewToFront(tabBar)
Is there a way to get both these features without using a separate view for creating shadows? Also what function is called for the tabBar to be hidden when a new ViewController is presented fullscreen?
I tried the solution given in this question, but didn't get shadow. Can't set tab bar shadow image in iOS 13