Swift Tab Bar remains translucent

33 Views Asked by At

I am trying to make a 'hump' tab bar controller with the post button as a featured tab, but for some reason the tab bar remains translucent no matter what I try. You can see it works well when there is not content presented, but once there is content you can see the color difference of the tab bar and the post button container.

How can I make my tab bar completely not translucent?

enter image description here enter image description hereenter image description here

enter image description here

in my MainTabBarViewController

func customizeTabBar() {
    postButtonContainer = UIView(frame: CGRect(x: 0, y: 10, width: tabBar.bounds.height + 30, height: tabBar.bounds.height + 30))
    postButtonContainer.center = CGPoint(x: tabBar.bounds.width / 2, y: tabBar.bounds.height / 3)
    postButtonContainer.backgroundColor = .white
    //UIColor.uStadium.takesLightestGray
    //tabBar.barTintColor = UIColor.uStadium.takesLightestGray
    
    postButtonContainer.layer.cornerRadius = postButtonContainer.frame.height / 2

    
    tabBar.addSubview(postButtonContainer)
    let bounds = CGRect(
        x: postButtonContainer.bounds.width / 10,
        y: postButtonContainer.bounds.height / 10,
        width: postButtonContainer.bounds.width / 1.25,
        height: postButtonContainer.bounds.height / 1.25
    )
    postButton = UIButton(frame: bounds)//postButtonContainer.bounds)
    postButton.setImage(UIImage(named:"create_button"), for: .normal)
    
    postButton.addTarget(self, action: #selector(showCompose), for: .touchUpInside)
    
    postButtonContainer.addSubview(postButton)
    
    let appearance2 = tabBar.standardAppearance
    appearance2.shadowImage = nil
    appearance2.shadowColor = nil
    self.tabBar.standardAppearance = appearance2
    // Set a custom background color for the tab bar
    tabBar.barTintColor = .white

    // Remove the default shadow from the tab bar
    tabBar.shadowImage = UIImage()

    // Set a custom shadow image for the tab bar
    tabBar.backgroundImage = UIImage(named: "custom_tabbar_background")

    // Set the tab bar item appearance to make the icons and text stand out
    let appearance = UITabBarItem.appearance()
    let attributes = [NSAttributedString.Key.foregroundColor: UIColor.gray]
    appearance.setTitleTextAttributes(attributes, for: .normal)
    let selectedAttributes = [NSAttributedString.Key.foregroundColor: UIColor.uStadium.green]
    appearance.setTitleTextAttributes(selectedAttributes, for: .selected)

    // Add shadow to the top of the tab bar
    tabBar.layer.shadowOffset = CGSize(width: 0, height: -3)
    tabBar.layer.shadowColor = UIColor.lightGray.cgColor
    tabBar.layer.shadowRadius = 5
    tabBar.layer.shadowOpacity = 0.5
    tabBar.isTranslucent = false
    tabBar.backgroundColor = .white
}
0

There are 0 best solutions below