Latest 1.1.0
Homepage https://github.com/wonderkiln/FlexTabBar
License MIT
Platforms ios 9.0
Authors

Flexible Tab Bar Header

Flexible Tab Bar is a custom approach to the tab bar that allows you to create different views for different orientations/devices or states. iOS default UITabBar is limited and it is really hard to customize it for different device states.

Preview

  • Portrait (with a different type of button in the middle and different presentation when tapped)

    FlexTabBar
  • Landscape (same tab layout as for the portrait one)

    FlexTabBar

And for iPad:

  • Portrait (the middle button is now placed at the end and has the same presentation style as the rest of the tab pages)

    FlexTabBar
  • Landscape (same tab layout as for the portrait one but now it displays the tab item title since it has more space to expand)

    FlexTabBar

Adding to your project

To add open-tab-bar via CocoaPods into your project just create a Podfile and add this line:

pod 'open-tab-bar'

Install the pod by running pod install

Usage

1. Extending the controller

First extend your view controller from WKTabBarController:

class ViewController: WKTabBarController {

}

2. Setting the items

You can set the items in the viewDidLoad function via the tabBarItems property:

tabBarItems = [
  WKTabBarItem(title       : TAB_ITEM_TITLE,
               image       : NORMAL_IMAGE,
               highlighted : HIGHLIGHTED_IMAGE, (OPTIONAL)
               selected    : SELECTED_IMAGE     (OPTIONAL)
  )
]

3. Customizing the items

WKTabBarController already implements the WKTabBarControllerProtocol, so in your ViewController you can override these methods in order to customize the appearance of the items:

func tabBarController(_ controller: WKTabBarController, cellNameAtIndex index: Int) -> WKTabBarCellName
func tabBarController(_ controller: WKTabBarController, customize cell: WKBaseTabBarCell, with item: WKTabBarItem, at index: Int)

The line below allows you to return the view controller that you want to be shown. If you decide you want to do something that doesn’t implies showing a controller just do you thing and then return nil.

func tabBarController(_ controller: WKTabBarController, viewControllerAtIndex index: Int) -> UIViewController?

4. Customizing the tab bar item

Create a class that extends the WKBaseTabBarCell class:

final class CustomTabBarItem: WKBaseTabBarCell {

}

In this class you can override these methods in order to customize the appearance of the item:

open func set(model: WKTabBarItem) // called when setting the tab bar model
open func commonInit()             // called when initialized
open func set(highlighted: Bool)   // called when the item should change its appearance on highlighted
open func set(selected: Bool)      // called when the item should change its appearance on selected

After this don’t forget to register the new class with this line:

self.register(cell: CustomTabBarItem.self, withName: "CustomTabBarItem")

And you can now return the custom cell to be displayed:

func tabBarController(_ controller: WKTabBarController, cellNameAtIndex index: Int) -> WKTabBarCellName {
  return "CustomTabBarItem"
}

Credits

Adrian Mateoaea

License

Latest podspec

{
    "name": "FlexTabBar",
    "version": "1.1.0",
    "summary": "Flexible Tab Bar for Swift",
    "homepage": "https://github.com/wonderkiln/FlexTabBar",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Adrian Mateoaea": "[email protected]"
    },
    "platforms": {
        "ios": "9.0"
    },
    "source": {
        "git": "https://github.com/wonderkiln/FlexTabBar.git",
        "branch": "master",
        "tag": "1.1.0"
    },
    "source_files": "WKTabBarController/**/*.swift",
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This