如何在TabBarController的TabBar下方添加imageView

问题描述 投票:0回答:1

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

谢谢。

ios swift uitabbarcontroller uitabbar
1个回答
0
投票

创建一个自定义类,从UITaabaecontroller继承它,并使用以下代码

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
    }

}

现在将自定义类设置为情节提要板中的Tabbarcontrollerenter image description here

© www.soinside.com 2019 - 2024. All rights reserved.