Swiftpack.co - Package - Minitour/AZTabBarController

AZTabBarController

A custom tab bar controller for iOS written in Swift 4.0

Screenshots

Installation

Cocoa Pods:

pod 'AZTabBar'

Swift Package Manager:

You can use The Swift Package Manager to install AZTabBarController by adding the proper description to your Package.swift file:

// swift-tools-version:4.0
import PackageDescription
let package = Package(
    name: "YOUR_PROJECT_NAME",
    dependencies: [
        .package(url: "https://github.com/Minitour/AZTabBarController.git", from: "1.4.2"),
    ]
)

Then run swift build whenever you're ready.

Manual:

Simply drag and drop the Sources folder to your project.

Usage:

Create an array of String/UIImage:

//The icons that will be displayed on the tabs that are not currently selected
var icons = [String](https://raw.github.com/Minitour/AZTabBarController/blob/master/)
icons.append("ic_star_outline")
icons.append("ic_history_outline")
icons.append("ic_phone_outline")
icons.append("ic_chat_outline")
icons.append("ic_settings_outline")

//The icons that will be displayed for each tab once they are selected.
var selectedIcons = [String](https://raw.github.com/Minitour/AZTabBarController/blob/master/)
selectedIcons.append("ic_star_filled")
selectedIcons.append("ic_history_filled")
selectedIcons.append("ic_phone_filled")
selectedIcons.append("ic_chat_filled")
selectedIcons.append("ic_settings_filled")

Now initialize the controller object through the following method:

tabController = .insert(into: self, withTabIconNames: icons, andSelectedIconNames: selectedIcons)

Add controllers:

//if you are using storyboard:
let myChildViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "ChildViewController")!

//if you are loading programmatically:
let myChildViewController = ChildViewController()

tabController.setViewController(myChildViewController, atIndex: 0)

Add actions:

tabController.setAction(atIndex: 3) { 
    //Your statments
    print("Hello World")
}

Note that you can add both actions and view controllers at a certain index.

Customizations:

//default color of the icons on the buttons
tabController.defaultColor = .white 

//the color of the icon when a menu is selected
tabController.selectedColor = .orange 

//The color of the icon of a highlighted tab
tabController.highlightColor = .white

//The background color of the button of the highlighted tabs.
tabController.highlightedBackgroundColor = .green

//The background color of the tab bar
tabController.buttonsBackgroundColor = .black 

//The color of the selection indicator.
tabController.selectionIndicatorColor = .green

// default is 3.0
tabController.selectionIndicatorHeight = 0 

// change the seperator line color
tabController.separatorLineColor = .black 

//hide or show the seperator line
tabController.separatorLineVisible = false 

//Enable tab change animation that looks like facebook
tabController.animateTabChange = true

Extras:

Make tab look highlighted:

tabController.highlightButton(atIndex: 2) 

Hide/Show the tab bar:

tabController.setBar(hidden: true, animated: true)

Add badge to menu (use nil value to remove existing badges):

tabController.setBadgeText("5", atIndex: 3)

Switch programmatically to a certain tab:

tabController.setIndex(2) //animated = true by default
//or
tabController.setIndex(2, animated: false)

Grant access to change the status bar style per tab:

override var childViewControllerForStatusBarStyle: UIViewController?{
    return tabController
}
//Then implement the delegate method:
func tabBar(_ tabBar: AZTabBarController, statusBarStyleForIndex index: Int) -> UIStatusBarStyle {
    return (index % 2) == 0 ? .default : .lightContent
}

Manage Titles

Adding Titles:

tabController.setTitle("Home", atIndex: 0)
tabController.setTitle("Search", atIndex: 1)
tabController.setTitle("Camera", atIndex: 2)
tabController.setTitle("Feed", atIndex: 3)
tabController.setTitle("Profile", atIndex: 4)

Show Title Only For Selected Index:

tabController.onlyShowTextForSelectedButtons = true

Access AZTabBarController from child view controllers:

I created an extension for UIViewController which adds a var called currentTabBar:

public var currentTabBar: AZTabBarController? { get }

You can call it like this:

currentTabBar?.setBadgeText("New Badge Value",atIndex: 2)

Delegate Methods:

These are the functions of the AZTabBarDelegate:

/// This function is called after `didMoveToTabAtIndex` is called. In order for this function to work you must override the var `childViewControllerForStatusBarStyle` in the root controller to return this instance of AZTabBarController.
///
/// - Parameters:
///   - tabBar: The current instance of AZTabBarController.
///   - index: The index of the child view controller which you wish to set a status bar style for.
/// - Returns: The status bar style.
func tabBar(_ tabBar: AZTabBarController, statusBarStyleForIndex index: Int)-> UIStatusBarStyle
/// This function is called whenever user clicks the menu a long click. If returned false, the action will be ignored.
///
/// - Parameters:
///   - tabBar: The current instance of AZTabBarController.
///   - index: The index of the child view controller which you wish to disable the long menu click for.
/// - Returns: true if you wish to allow long-click interaction for a specific tab, false otherwise.
func tabBar(_ tabBar: AZTabBarController, shouldLongClickForIndex index: Int)-> Bool
/// This function is used to enable/disable animation for a certian tab.
///
/// - Parameters:
///   - tabBar: The current instance of AZTabBarController.
///   - index: The index of the tab.
/// - Returns: true if you wish to enable the animation, false otherwise.
func tabBar(_ tabBar: AZTabBarController, shouldAnimateButtonInteractionAtIndex index:Int)->Bool
/// This function is called whenever user taps one of the menu buttons.
///
/// - Parameters:
///   - tabBar: The current instance of AZTabBarController.
///   - index: The index of the menu the user tapped.
func tabBar(_ tabBar: AZTabBarController, didSelectTabAtIndex index: Int)
/// This function is called whenever user taps and hold one of the menu buttons. Note that this function will not be called for a certain index if `shouldLongClickForIndex` is implemented and returns false for that very same index.
///
/// - Parameters:
///   - tabBar: The current instance of AZTabBarController.
///   - index: The index of the menu the user long clicked.
func tabBar(_ tabBar: AZTabBarController, didLongClickTabAtIndex index:Int)
/// This function is called before the child view controllers are switched.
///
/// - Parameters:
///   - tabBar: The current instance of AZTabBarController.
///   - index: The index of the controller which the tab bar will be switching to.
func tabBar(_ tabBar: AZTabBarController, willMoveToTabAtIndex index:Int)
/// This function is called after the child view controllers are switched.
///
/// - Parameters:
///   - tabBar: The current instance of AZTabBarController.
///   - index: The index of the controller which the tab bar had switched to.
func tabBar(_ tabBar: AZTabBarController, didMoveToTabAtIndex index: Int)

Credits

AZTabBarController was originally inspired by ESTabBarController that is written in Objective-C by ezescaruli.

Thanks to Tobaloidee for creating the logo.

Github

link
Stars: 254

Used By

Total: 0

Releases

Version 1.4.2 - 2019-04-12 19:24:03

  • Made AZTabBarController open. Now the class can be subclassed and extended. Close #48.
  • Fixed bug when unwrapping optional values. Close #53.
  • Fixed bug where highlighted button title would not get the highlight tint. Close #41.

Release 1.3.2 - 2018-02-22 15:22:40

Fixed a bug that caused a crash.

Swift 4.0 Support - 2017-11-03 14:38:24

iPhone X Support - 2017-10-24 13:09:42

Version 1.2.2 - 2017-07-16 09:34:27

  • Added Title Support.
  • Changed View hierarchy .
  • Added removeHighlight function.
  • Added setTitle function.
  • Added getTitle function.
  • Added onlyShowTextForSelectedButtons variable.
  • Added font variable.

Fixed Constraint Bug - 2017-05-31 18:55:44

Improved Source,Added new APIs - 2017-05-18 21:42:25

  • Updated constraints to the new constraints API of iOS 9.0

  • Added new APIs:

    • insertTab: Insert a tab at a certain index.
    • removeTab: Remove a tab at a certain index.
    • setTabIcon: Change the tab icon at a certain index.
  • Updated source code structure.

Version 1.1.3 - 2017-04-26 14:12:47

  • Added shouldMoveToTabAtIndex
  • Added removeViewController
  • Added removeAction
  • Fixed selection indicator glitch

Added New Transition Effect, Changed Method Names - 2017-04-17 14:35:12

Added new Transition Effect, disabled by default, use .animateTabChange = true to enable it.

Changed methods names: .set(badgeText: , atIndex:) to .setBadgeText(:,atIndex:)

.set(viewController:,atIndex:) to .setViewController(:,atIndex:)

.set(selectedIndex:,animated:) to .setIndex(:,animated:)

.set(action:, atIndex:) to .setAction(atIndex: Int, action:)

Added Extra default parameters to .setBar

Fixed Bug - 2017-04-13 15:47:11

Fixed bug where if you set the current index before loading the view it would crash.

Version 1.1.0 - 2017-04-11 21:13:00

Added:

  • highlightColor
  • highlightedBackgroundColor
  • ignoreIconColors

Updated:

  • Made delegate optional and weak.
  • Made controllers an array of optional UIViewController instead of NSMutableDictionary.
  • Made actions an array of optional AZTabBarAction instead of NSMutableDictionary.

Made some small modifications and bug fixes.

Added a public extension for UIViewController which allows access to a var called currentTabBar. This var is an optional AZTabBarController. If there is no tab bar it will return nil.

Fixed nil badge value issue - 2017-02-14 22:14:26

Fixed a bug where on launch the tab bar could cause a crash by trying to access an nil value.

System Sound Support - 2017-02-06 11:58:29

  • Added an option to play a sound effect after clicking a tab.
  • Fixed nil delegate crash

Improved UI and UX - 2017-02-03 16:10:58

Added bounce animation for each tab. Added more customization options. Added more documentation. Removed XIB (AZTabBarController is loaded 100% programmatically now).

Delegate Support - 2017-01-11 15:05:41

- 2017-01-10 20:28:52

  • Added support for 2 icon versions, this means you can now set an image for selected mode and default mode.
  • Added documentation.
  • Added notificationBadgeAppearance property to allow you to design the badge as well.
  • Made the property selectedIndex read only.

- 2017-01-10 09:51:54

- 2017-01-10 09:48:51

- 2017-01-08 16:11:34

- 2017-01-08 12:32:03

- 2017-01-08 12:02:04