ios - 如何在 TabBarController 的 TabBar 下添加 imageView

标签 ios swift uitabbarcontroller uitabbar

enter image description here我想在 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
    }

}

现在将自定义类设置为 Storyboard中的 Tabbarcontroller
enter image description here

关于ios - 如何在 TabBarController 的 TabBar 下添加 imageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58876635/

相关文章:

ios - 将参数传递给作为参数的选择器

ios - 如何在同一类中使用警报和微调器?

swift - 为什么两阶段初始化不适用于 swift 中的类?

ios - 获取函数的地址 [Swift 3.0]

ios - UIStepper 的值(value)

iOS 内存管理/持久性问题

ios - 在两个 tabbarcontroller 之间进行 Segue

iphone - 标准 View 和 UITabBarController View 之间的转换?

ios - "Default"在 UITabBarController 中查看

ios - 如何在 UIPageViewController 上禁用多点触控?