Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Custom Tab Bar

I am looking to implement a custom Tab Bar in iOS where selected item is bigger size than the rest of the tabs and peeks out over the content similar to this screenshot. enter image description here

Could someone point to a tutorial of how to accomplish this preferably in Swift?

like image 513
AlexVPerl Avatar asked Jan 14 '17 00:01

AlexVPerl


People also ask

How do I add items to my tab bar controller?

To add a tab, first drag a new View Controller object to the storybard. Next control-drag from the tab bar controller to new view controller and select view controllers under Relationship Segue . Your tab bar controller will update with a new tab.


2 Answers

I faced with this task several times. I found a lot of tutorials but I've never found one that gives the ability to create a center button that part of it is out of the tab bar.

At the end, I created an approach to have it done correctly. I implemented a simple example project with instructions how to do that. Please check my Custom Tabbar Center Button repo as an example.

One more benefit of it it's center button hides correctly with the tab bar when you use Hide Button Bar on Push property.

enter image description here

like image 100
Rostyslav Druzhchenko Avatar answered Sep 28 '22 21:09

Rostyslav Druzhchenko


A UITabBar contains an array of UITabBarItems, which inherit from UIBarItem. But unlike UIBarButtonItem that also inherits from UIBarItem, there is no API to create a UITabBarItem with a customView.

So instead of trying to create a custom UITabBarItem, we’ll just create a regular one and then put the custom UIButton on top of the UITabBar

Not swift, but should be easily translated.

https://github.com/boctor/idev-recipes/tree/master/RaisedCenterTabBar

This one is Swift: https://github.com/itsKaynine/SwiftRaisedTab

Source code for a similar question, using Swift 3: https://stackoverflow.com/a/36016377/300897

like image 34
bradenkeith Avatar answered Sep 28 '22 20:09

bradenkeith