[iOS SDK] Changing TabBar order in a storyboard

In a storyboard-based app containing an UITabBarController with various ViewControllers as tabs, the need of changing the tab’s order is very frequent due to changes in the App’s requirements.

There are various ways of doing that. In my opinion, the most elegant one is doing the steps above:

1.- Open Xcode, open the current project. In the project structure (left menu), right click on the desired .storyboard file. Select “Open as > Source code”
2.- Inside the enormous XML file, find a tag with a tag inside it. The Find command (CMD+F) might be helpful.
3.- You might have several tags with attributes “destination”,”kind”,”relationship” and “id”; One on each line. Change the lines to the order of your preference (for example, the fourth becomes the first, the second is swapped with the third, etc). Useful keyboard shortcuts: ALT+arrow_up, ALT+arrow_down.
4.- Save (CMD+S) the file, again right click on the .storyboard and select “Open as > Interface Builder”. You might see your tabs in the desired order 🙂

Another useful thing: Inside the tag (could be also , or another derived class), you can set the “title” attribute. This value will be the text displayed as the tab name. More info in this SO question

Have a nice coding day!

Advertisements