如何将自定义 tabBar 设置为我的自定义 TabBarController?

you*_*afa 1 iphone xcode ios autolayout swift

我的自定义标签栏:

class MyTabBar: UITabBar {

}

My custom tab Bar Controller: 

class MyTabBarController: UITabBarController {

}
Run Code Online (Sandbox Code Playgroud)

我的问题是如何在我的自定义标签栏控制器中使用我的自定义标签栏?

you*_*afa 5

我通过将“tabBar”的值设置为我的自定义 tabBar 来做到这一点。

setValue(MycustomTabBar(frame: tabBar.frame), forKey: "tabBar")

class MyCustomTabBarController: UITabBarController {
override func viewDidLoad() {
        super.viewDidLoad()
        setValue(TBar(frame: tabBar.frame), forKey: "tabBar")
        view.backgroundColor = .white
        createShape()
    }
}
Run Code Online (Sandbox Code Playgroud)

  • 这是一个糟糕的解决方案,因为你涉及私有 api (2认同)