­

Swift + UITabBarController

By 10:48

So last week we talked about whether to place hamburgers menus in your application.
TLDR: the answer is preferably no.
In that case, let's see how we'll create a UITabBarController.

Making an UITabBarController is fairly simple if you didnt select an Tabbed Application when you first made your app. You can go about this in 2 ways. Either you drag in a tab bar controller from the object library:



Or by converting your current view controller in a Tab Bar Controller:


Either way now you have a Tab Bar Controller in which you can make your tab bars. What you'll see is that another Viewcontroller came along with the Tab Bar Controller. You can make your changes in this new Viewcontroller by double tapping on the label like so:


If you wanna add another tab to your Tab Bar Controller, you can do so by adding a new ViewController in your storyboard and connecting thiss new ViewController and the Tab Bar Controller by segue(pronounced: segway):

Select "view controllers" to create the segue
And yes! You'll see that another tab has been added to your Tab Bar Controller which you can customise with your own title and icon.
Just make sure your icon is available in the correct sizes. If you go to your Images group in your project and you click or add an basic icon thats used in the app, you'll see that there are 3 sizes: 1x, 2x, 3x. 
These different sizes are to make sure that the icons will be shown nicely in different kinds of resolutions. So make sure when you want to make use of an icon, you'll have to resize it in different sizes and drag those into the project. For the Tab Bar Controller the following sizes need to be put into the images group:
(more info about what sizes for what icons can be found here: https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/MobileHIG/IconMatrix.html#//apple_ref/doc/uid/TP40006556-CH27-SW1)
In the attributes inspector you can choose the icon you would like for your tab and your project will select the correct size of icon automatically based on which device its being used. Its like magic!



0 reacties