Only image as UITabBarItem

后端 未结 9 2180
伪装坚强ぢ
伪装坚强ぢ 2021-02-01 05:29

I would only like to have an icon as the UITabBarItem and not the text underneath and I was wondering if this was possible, if so, how? TIA

9条回答
  •  Happy的楠姐
    2021-02-01 05:44

    I know its been quite some time. But I might have a solution for this problem.

    @ThiagoPires answer is useful only if the image is big enough to cover the title. In case if it isn't, then the title will be visible under the image.

    I think that the easiest way to accomplish this, is by setting the title of the tabBarItem to "" in your view controllers code.

    It is important to know that every time you change your view controllers title, the tabbaritem's title will be updated too. You could go fancy using KVO to observe the title's change and set "" to the tabbaritem title accordingly. But if you don't change it in many places in your code, you could just set it right in the place you change the ViewController's title.

    Here is an example in swift:

    override func viewDidLoad() {
    
        super.viewDidLoad()
    
        self.title = "View controller's Title"
    
        self.tabBarItem.title = ""
    }
    

    That's it. I hope that this could help.

提交回复
热议问题