Giter Club home page Giter Club logo

helargecentertabbarcontroller's Introduction

Build Status CocoaPods Compatible License Platform

HELargeCenterTabBarController

HELargeCenterTabBarController is a 100% Swift implementation of a UITabBarController with a lager center 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.

Simple. Lightweight. To-the-point.

Typical Use:

alt tag

Alternate approach (allowSwitch = false)

alt tag

Supported OS and SDK

  • Xcode 9+
  • Swift 4+
  • iOS 8 (minimum, required)

As of v2.1, only Swift 4 is supported. If you need Swift 3 support, use v2.0. As of v2.0, only Swift 3 is supported. If you need Swift 2.2 support, use v1.0.1.

Installation

Currently supports being installed by simple source code addition, by git submodule, or by CocoaPods (preferred).

Submodule

You can easily obtain git as a submodule, and simply add HELargeCenterTabBarController.swift to your project. Off you go!

CocoaPods

CocoaPods is a dependency manager for Cocoa projects.

CocoaPods 0.36 adds supports for Swift and embedded frameworks. You can install it with the following command:

$ gem install cocoapods

To integrate HELargeCenterTabBarController into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

pod 'HELargeCenterTabBarController'

Then, run the following command:

$ pod install

Usage

Instantiate the HELargeCenterTabBarController either in code or in your storyboard.

Setup

Storyboard

  • Drag a UITabBarController from the Interface Builder Object Library into your Storyboard.
  • Select the UITabBarController instance, switch to the "Identity Inspector" tab, and set the custom class to HELargeCenterTabBarController.
    • You may need to set the Module, depending how you added HELargeCenterTabBarController to your project.
  • Have some way to obtain a reference to the HELargeCenterTabBarController instance, so you can call addCenterButton() on it. This could be:
    • via an IBOutlet
    • As the controller is likely the appDelegate.window?.rootViewController?, you could access it that way.

Code

In your application(application:didFinishLaunchingWithOptions:):

private var tabController: UITabBarController!

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
   
   // create your content view controllers
   
   tabController = HELargeCenterTabBarController()
   tabController.viewControllers = [firstViewController, secondViewController, thirdViewController]
   // addCenterButton() -- see below
   window?.rootViewController = tabController
   
   return true
}

Common

Assuming you now have instantiated a HELargeCenterTabBarController and have a reference to it, you add your button images thusly:

if let unselectedImage = UIImage(named: "tab-unselected"), selectedImage = UIImage(named: "tab-selected") {
    tabController.addCenterButton(unselectedImage: unselectedImage, selectedImage: selectedImage)
}

It's important to ensure your call to addCenterButton() happens after the HELargeCenterTabBarController actually loads (its viewDidLoad() is called). Depending upon the timing of how things are created, it you may need to wrap your add in a dispatch_async() to ensure this ordering:

dispatch_async(dispatch_get_main_queue(), { () -> Void in
    if let unselectedImage = UIImage(named: "tab-unselected"), selectedImage = UIImage(named: "tab-selected") {
        tabBarController.addCenterButton(unselectedImage: unselectedImage, selectedImage: selectedImage)
    }
})

Images

The images wholly define the look and feel of the center button/tab. The colors, borders, transparency, icons, labels, and most importantly size of the tab come 100% from the images.

It is expected to provide two versions of the same image: a selected and an unselected image. The selected image is used when the tab is selected, and cosmetics should reflect a selected state (e.g. "brighter"). The unselected image is used when the tab is not selected, and cosmetics should reflect an unselected state (e.g. dimmer, subdued, disabled).

It's important the two images are the same size and general look and feel, differing only in reflection of (un)selected state. This provides the seemless UI and UX needed to make this control work.

Target-Action

Because the tab is actually implemented as a UIButton, a optional target-action is supported for taps on the button. Having a target-action is generally not necessary, if all you desire is typical tab-like functionality, just with the larger-center cosmetics.

One place where target-action is required is if allowSwitch is false.

allowSwitch

While the controller's typical behavior is to act in a tab-like manner, where tapping the tab button switches the content to the ViewController associated with that tab, setting allowSwitch to false will prevent the switch from occurring. The tap still occurs, just no switching occurs. Instead, you will want to install a target-action to execute your behavior.

One reason for this might be that instead of switching to a different tab, a ViewController is presented modally. For example:

tabController.addCenterButton(unselectedImage: unselectedImage, selectedImage: selectedImage, target: self, action: "presentSecondViewController:", allowSwitch: false)

...

func presentSecondViewController(sender: AnyObject) {
    if let rootViewController = window?.rootViewController {
        let viewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("modalNavViewController")
        rootViewController.presentViewController(viewController, animated: true, completion: nil)
    }
}

Contact

Hsoi Enterprises

Creator

Changes / Release Notes

See included CHANGELOG.md file.

License

BSD 3-clause “New” or “Revised” License. See included "License" file.

helargecentertabbarcontroller's People

Contributors

hsoi avatar dodgecm avatar wwgilpin avatar readmecritic avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.