iOS 5 By Tutorials ebook

MHTabBarController – A custom tab bar for iOS 5 using the new container APIs

Creating your own container view controllers, i.e. view controllers that can contain other view controllers, used to be a pain but now iOS 5 makes it a lot easier.

Especially for iPad apps that is great, because all of that screen space means you probably want to divide it up amongst more than one view controller.

Today I was messing around with these new container APIs and built my own tab bar controller. It works just like a regular UITabBarController, except the tabs look quite different and the pages slide in and out of the screen with a nice animation.

Screenshot of MHTabBarController in the demo app
If you want to learn more about how to do this, then check out the source code or get the iOS 5 by Tutorials ebook. It has a full chapter on these new view controller containment APIs, plus twenty or so other chapters on more iOS 5 goodness!

Comments

  1. valshebnik says:

    Thanks for sharing Matthijs, it looks pretty interesting. BTW I think it’s a good practice to write some useful stuff to strengthen and polish the gained knowledge :]
    A few questions regarding the source code.
    - What the “\file” marker in header comment block is for?
    - Why are you using floorf() function in MHTabBarController.m, line 44 and later?
    - Is there any _practical_ reason to explicitly specify float type of literals?
    And I have to admit your code is very readable. Could you please write a post about code readability, maybe some not so obvious rules people could keep in mind while writing code.

  2. Matthijs says:

    Hi valshebnik,

    1) The \file marker is for the Doxygen documentation generation tool.

    2) I use floorf() to round the number to the nearest integer (rounding down always). This is necessary to prevent the image from being placed in between two pixels, for example at pixel 36.5, which will make it blurry.

    3) By putting the “f” behind a number you tell the compiler it is a float instead of a double (or integer). It probably doesn’t make much difference in practice, though.

  3. valshebnik says:

    2) Good point! Never thought about that. Will do the same from now on. 3) I noticed many times folks are doing the same, but I haven’t found any practical meaning in that yet. Was hoping you spill some light on it as always :]
    Thanks for the answers.

  4. Jesper says:

    Re #3: iDevices (starting with the 3GS, iirc) handle floats much faster than doubles. You likely won’t notice any difference most of the time though.

    I tend to denote my numbers with “f” as well (unless I specifically need double accuracy). It doesn’t cost anything at the very least. :)

  5. Alexander Kholodov says:

    Good idea, any reason you’re not releasing the memory?
    dealloc doesn’t exist, viewDidUnload method is losing pointers, instead of releasing the memory

  6. Matthijs says:

    @Alexander This is written for iOS 5 and therefore uses ARC. The cool thing about ARC is that you no longer have to worry about memory management, it is done automatically for you now.

Leave a Reply

Your email address is required but will not be visible to others.

*
*