Search code examples
iphoneiosuitabbarcontrolleruitabbar

Custom TabBar inside a View iOS


I'm trying to add a some tabs into a single view so the user can add multiple items.

example

As you can see the content of the tab does not take the whole view, just a little bit, the bar is in the middle and the stuff above it does not change when tabs change. The content is the same for the 5 views.

I haven't been able to find a way to replicate this on iOS, any ideas?

Thanks in advance!


Solution

  • There are 3 ways to replicate this:

    1) use a UISegmentedControl. This gives you the desired functionality, but you may not be able to make it look exactly the way you have it in the image. This is the simplest and the easiest way to solve your problem.

    2) use 5 custom UIButtons placed next to each other, manage the states of the buttons, and assign images to these buttons based on their selection state. If button 1 is pressed, its background image will be "lightRedImage", and all other buttons will be "darkRedImage", and so on. This is a better option if you don't want to use too many images, but there is a bit more code to handle the button states.

    3)For this you'll need whole image of the background, for all 5 selected states. Create an imageView that is 5 buttons wide. Place 5 custom buttons, with clearColor as background on this imageView. if button1 is tapped, button1's action method will set the imageView.image to "highlightButton1.png". This is better if you don't mind having the backgroundImage for the 5 different possible states, and it is less code, since the only thing you have to do to update the UI is to change the background of that imageView.

    Note: With a UITabBar and UISegmentedControl, the voiceover functionality comes free of cost. With options #2 and #3, its up to you to add the UIAccessibility properties to reflect the selection states etc. So, if you are bothered about Accessibility and VoiceOver functionality of your app, you should keep this in mind. (If you don't know what these are, or are not bothered, read this)