Skip to content

A custom PageViewController for iOS with the tab bar control at the top

License

Notifications You must be signed in to change notification settings

ThomasNguyenGitHub/EVTopTabBar

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EVTopTabBar

CI Status Version License Platform

About

EVTopTabBar is a custom UIPageViewController for iOS where the page control is at the top. It currently supports two tabs.

Screenshot0

Usage

To run the example project, clone the repo, and run pod install from the Example directory.

Requirements

  • Swift 2.0+
  • iOS 8.0+

Installation

EVTopTabBar is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "EVTopTabBar"

Also include

use_frameworks!

Getting Started

import EVTopTabBar

Implement the EVTabBar protocol and conform to it. In order to conform to the protocol declare:

var pageController = UIPageViewController(transitionStyle: .Scroll, navigationOrientation: .Horizontal, options: nil)
//need to instantiate the topTabBar itself, later we will implement the delegate method
var topTabBar: EVPageViewTopTabBar = EVPageViewTopTabBar()
//array of view controllers that will be controlled by the page view controller
var subviewControllers: [UIViewController] = []
//image from the sample project can use any UIImage you want, this shadow is what is displayed under the tab bar.
var shadowView = UIImageView(image: UIImage(imageLiteral: "filter-background-image"))

Now in your view controller implement the EVPageViewTopTabBarDelegate method willSelectViewControllerAtIndex This method allows for view controllers to switch and gives a space to perform any other actions.

extension ViewController: EVPageViewTopTabBarDelegate {
	//delegate method
    func willSelectViewControllerAtIndex(index: Int, direction: UIPageViewControllerNavigationDirection) {
    	//required line that changes the displayed view controller
        pageController.setViewControllers([self.subviewControllers[index]], direction: direction, animated: true, completion: nil)
        //add whatever code you wish to occur on the transition!
    }
}

Next will want to call the setupPageView() and setupConstraints() methods in order to setup the page layout. You can override both of these methods to create a more custom application.

Lastly you will want to setup the topTabBar you previously declared

//attributes of the topTabBar you can set
topTabBar.fontColors = (selectedColor: UIColor.grayColor(), unselectedColor: UIColor.lightGrayColor())
topTabBar.rightButtonText = "Events"
topTabBar.leftButtonText = "Contacts"
topTabBar.labelFont = UIFont(name: ".SFUIText-Regular", size: 11)!
topTabBar.indicatorViewColor = UIColor.blueColor()
topTabBar.backgroundColor = UIColor.whiteColor()
topTabBar.setupUI()
//ensure you set the topTabBar's delegate
topTabBar.delegate = self
//add view controllers you wish to display
let firstVC = FirstViewController(nibName:"FirstViewController", bundle: nil)
let secondVC = SecondViewController(nibName:"SecondViewController", bundle: nil)
subviewControllers = [firstVC, secondVC]

Project description

EVTabBar Protocol

Methods

  • setupPageView() Sets the UI for the View Controller including the UIPageViewController, shadowView and View Controllers to display inside of the Page View.
  • setupConstraints() Sets the initial constraints for the View Controller

EVPageViewTopTabBar

Methods

  • setupUI() Sets the UI for the tab bar itself
  • willSelectViewControllerAtIndex(index: Int, direction: UIPageViewControllerNavigationDirection) Controls the changing of the View Controllers inside of the PageViewController and gives a space to perform any other actions on transition

Future Features

  • Support for more tabs
  • More flexibility with the shadow view

Author

Eric Vennaro, [email protected], blog

License

EVTopTabBar is available under the MIT License. See the LICENSE file for more info.

Copyright © 2016-present Eric Vennaro.

About

A custom PageViewController for iOS with the tab bar control at the top

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Shell 46.9%
  • Swift 45.0%
  • Ruby 5.5%
  • Objective-C 2.6%