Announcing HELargeCenterTabBarController – more 100% Swift open source

hsoi blog, news 0 Comments

Hsoi Enterprises LLC is excited to announce another addition to our open source code libraries:

HELargeCenterTabBarController

Based on the name, you might be able to guess what it is: a UITabBarController subclass that supports an enlarged center button/tab. The center tab can be used in the typical manner where a tap switches to display the associated ViewController, or the center tab can be used in an alternate manner where the tap does not switch ViewControllers but instead executes a target-action.

Here’s what the typical use looks like:

Typical tab-like behavior

Typical tab-like behavior

And here’s what the alternative use looks like:

Alternative button-like behavior

Alternative button-like behavior

This is code I created over a year ago to solve a problem in an app I’ve been working on. A colleague needed this behavior in an app he’s working on, so I shared my code with him thinking he’d use it as inspiration for his own implementation. He told me my code satisfied his need with one minor addition (allowSwitch), so I quickly made a GitHub repository so he could use the code. Well, as long as I officially open-sourced it, I figured it would be best to make it official. So this 1.0 release brings an official distribution, license, Cocoapods support, and… I rewrote it in Swift.

While the class is fairly simple, I found the Swift implementation preferable over the Objective-C implementation because the Swift language lets me do things I cannot do in Objective-C (or I can but requires more work). For instance, optional vs. non-optional allowed me to make it clear that the two images are required, which then allowed me to remove a lot of guard code. Or that Swift supports default arguments, which allowed removal of redundant convenience functions and also allowed the API to be more concise.

Hope you like it!

Share & Enjoy.

Leave a Reply