【问题标题】:How to add imageView down the TabBar in TabBarController如何在 TabBarController 中的 TabBar 下添加 imageView
【发布时间】:2019-11-15 12:01:18
【问题描述】:

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

谢谢。

【问题讨论】:

  • TabBarController 在其他 ViewController 的容器视图中,并将该图像添加到该容器视图中。这能解决你的问题吗?
  • 以下解决方案对您有帮助吗?

标签: ios swift uitabbarcontroller uitabbar


【解决方案1】:

创建一个自定义类,继承自 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
    }

}

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-10
    • 1970-01-01
    • 2018-12-19
    • 1970-01-01
    相关资源
    最近更新 更多