Search code examples
iosuitabbarcontrollerstoryboarduitabbar

iOS Custom TabBar and Storyboards


I am following a post here showing how to add a custom center tab bar item.

What's the best way of adding a custom centre button to a tab bar?

My only question is where should the code be put? I am using storyboards and right now I have it placed in viewwillappear for my default view that is shown. Should this go in a more generic or global area?


Solution

    1. Create a subclass of the UITabBarController, say MyTabBarController.
    2. In the storyboard, drag the standard UITabBarController into the scene, and change its class type to MyTabBarController.
    3. In the MyTabBarController, insert the code within its viewDidLoad method. If you put it within the viewwillappear method, it will be added multiple times since the viewwillappear will be called every time the tabbarcontroller is displayed.