我想在 TabBarController 中的 TabBar 下面/下面添加一个 imageView 有没有办法做到这一点。我搜索了很多关于在其他 ViewController 的容器 View 中添加 TabBarController 并将该图像添加到该容器 View 中的答案。我也尝试以编程方式添加图像,但它覆盖了 TabBar。 那么我该怎么做呢?如有任何建议,我们将不胜感激。
谢谢。
最佳答案
创建一个继承自 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
}
}
关于ios - 如何在 TabBarController 的 TabBar 下添加 imageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58876635/