Search code examples
iosswiftuitabbarcontrolleruitabbar

How to add imageView down the TabBar in TabBarController


enter image description hereI want to add a imageView below/down the TabBar in TabBarController is there any way to do that. I searched a lot got one answer about adding the TabBarController in other ViewController's container view and add that image down that container view. I also try to add image programmatically but it covers the TabBar. So how can i do that any suggestion would be appreciated.

Thank You.


Solution

  • Create one custom class inherit it from UITabarController and use the following code

    class CustomTabbarController: UITabBarController {
    
        override func loadView() {
            super.loadView()
            let imageView = UIImageView(frame: CGRect(x: 0, y: self.view.frame.size.height - 10, width: self.view.frame.size.width, height: 10))
            imageView.backgroundColor = UIColor.red // set image you wanted to show
            self.view.addSubview(imageView)
        }
    
        override func viewDidLayoutSubviews() {
                    tabBar.frame.origin.y = self.view.frame.size.height - 60 // change it according to your requirement
        }
    
    }
    

    Now set the custom class to the Tabbarcontroller inside storyboard
    enter image description here