How can I substitute the UITabBar of UITabBarController programmatically

后端 未结 2 1523
情歌与酒
情歌与酒 2021-01-15 13:49

I need to use a subclass of the UITabBar for my project because of the following problem Why page Push animation Tabbar moving up in the iPhone X.

I do not use stor

2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-15 14:10

    The reason you're getting the 'customTabBar.Type' error is because you're returning the name of your class which, against normal convention, is camel cased. You want to be returning an object - an instance of your class - instead.

    import UIKit
    
    @objc class customTabBarController: UITabBarController {
        let myCustomTabBar = customTabBar() // If we're writing conventional swift,
                                            // this should be CustomTabBar()
        
        override var tabBar: UITabBar {
            // Because your class name is customTabBar instead of CustomTabBar,
            // this is returning a TYPE instead of an OBJECT
            // return customTabBar
    
            // If you wanted to return a new version of a tab bar on every
            // get of this object, you'd use the following code which is similar to yours:
            // return customTabBar()
    
            // More likely, you want to return the SAME tabBar throughout this object's
            // lifecycle.
            return myCustomTabBar
        }
    }
    

提交回复
热议问题