如何在 TabBarController 的 TabBar 下添加 imageView

How to add imageView down the TabBar in TabBarController

我想添加一个 imageView below/down TabBarController 中的 TabBar 有没有办法做到这一点。我搜索了很多关于在其他 ViewController 的容器视图中添加 TabBarController 并将该图像添加到该容器视图中的答案。我也尝试以编程方式添加图像,但它覆盖了 TabBar。 那么我该怎么做呢?如有任何建议,我们将不胜感激。

谢谢。

创建一个自定义class继承自UITabarController并使用以下代码

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
    }

}

现在将自定义 class 设置为故事板中的 Tabbarcontroller