Code Monkey home page Code Monkey logo

tabman's Introduction

Tabman

Build Status Swift 3.0 CocoaPods codecov GitHub release

Tabman is a powerful paging view controller with indicator bar, for iOS.

Tabman

Features

  • Super easy to implement page view controller with indicator bar.
  • Multiple indicator bar styles.
  • Simplistic, yet highly extensive customisation.
  • Full support for custom components.
  • Built on a powerful and informative page view controller, Pageboy.

Installation

CocoaPods

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

pod 'Tabman'

And run pod install.

Dependencies

Example

A nice pretty example project is available to take a look at some of the features that Tabman offers. To run the example, simply clone the repo, run pod install and build the workspace.

Requirements

Tabman requires iOS 9.0 or above.

Usage

Getting Started

  1. Create an instance of TabmanViewController and provide it with a PageboyViewControllerDataSource. Note: TabmanViewController conforms to and is set as the PageboyViewControllerDelegate.
class YourTabViewController: TabmanViewController, PageboyViewControllerDataSource {

	override func viewDidLoad() {
		super.viewDidLoad()

		self.dataSource = self
	}
}
  1. Implement the PageboyViewControllerDataSource and configure the bar for display.
func viewControllers(forPageboyViewController pageboyViewController: PageboyViewController) -> [UIViewController]? {
    // return array of view controllers
    let viewControllers = [viewController1, viewController2]

    // configure the bar
    self.bar.items = [TabmanBarItem(title: "Page 1"),
                      TabmanBarItem(title: "Page 2")]

    return viewControllers
}

func defaultPageIndex(forPageboyViewController pageboyViewController: PageboyViewController) -> PageboyViewController.PageIndex? {
    // use default index
    return nil
}
  1. All done! ๐Ÿป

Doing a bit more

As Tabman is based on Pageboy, everything behaves the same and all the same properties/functions are available. Such as these functions for navigation & reloading:

// Scroll the page view controller to a new page.
public func scrollToPage(_ pageIndex: PageIndex,
                         animated: Bool,
                         completion: PageTransitionCompletion? = nil)

// Reload the view controllers in the page view controller.                         
public func reloadPages()

Read up on the Pageboy docs to find out a bit more here.

Customisation

The TabmanBar in Tabman can be completely customised to your liking, by simply modifying the available properties in the .bar TabmanBarConfig object.

Style

The style of bar to display, by default this is set to .scrollingButtonBar.

Available Styles:

Pageboy

For examples on implementing real-world bar styles with Tabman, check out Tabman-Styles.

Location

Where you want the bar to appear, either at the top or bottom of the screen. By default this is set to .preferred which will use the predefined preferred location for the active style.

The bar will automatically take UIKit components such as UINavigationBar and UITabBar into account.

Appearance

The TabmanBarAppearance object provides all the available properties for appearance customisation of a TabmanBar. Not all of the properties are appropriate for each style TabmanBar, therefore the bar will only respond to the properties it adheres to.

To set a custom appearance definition do this on a TabmanViewController:

tabViewController.bar.appearance = TabmanBar.Appearance({ (appearance) in
	// customise appearance here
	appearance.text.color = UIColor.red
	appearance.indicator.isProgressive = true
})

The following properties are available:

/// Indicator configuration
public struct Indicator {
	/// The preferred style to use for the indicator.
	/// This is optionally conformed to by the bar.
	public var preferredStyle: TabmanIndicator.Style?
	/// The color of the bar indicator.
	public var color: UIColor?
	/// The weight (thickness) of the bar indicator if using a line indicator.
	public var lineWeight: TabmanIndicator.LineWeight?
	/// Whether the indicator transiton is progressive.
	public var isProgressive: Bool?
	/// Whether the indicator bounces at the end of page ranges.
	public var bounces: Bool?
	/// Whether the indicator compresses at the end of page ranges.
	public var compresses: Bool?
	/// Whether to use rounded corners on line indicators.
	public var useRoundedCorners: Bool?
}

/// State configuration.
public struct State {
	/// The color to use for selected items in the bar (text/images etc.).
	public var selectedColor: UIColor?
	/// The text color to use for unselected items in the bar (text/images etc.).
	public var color: UIColor?
}

/// Text configuration
public struct Text {
	/// The font to use for text labels in the bar.
	public var font: UIFont?
}

/// Layout configuration
public struct Layout {
	/// The spacing between items in the bar.
	public var interItemSpacing: CGFloat?
	/// The spacing at the edge of the items in the bar.
	public var edgeInset: CGFloat?
	/// The height for the bar.
	public var height: TabmanBar.Height?
   	/// The vertical padding between the item and the bar bounds.
	public var itemVerticalPadding: CGFloat?
}

/// Bar style configuration.
public struct Style {
  /// The background style for the bar.
  public var background: TabmanBarBackgroundView.BackgroundStyle?
  /// Whether to show a fade on the items at the bounds edge of a scrolling button bar.
  public var showEdgeFade: Bool?
  /// Color of the separator at the bottom of the bar.
  public var bottomSeparatorColor: UIColor?
}

/// Bar interaction configuration
public struct Interaction {
    /// Whether user scroll is enabled on a scrolling button bar.
    public var isScrollEnabled: Bool?
}
Defaults

A number of default properties are set on TabmanBar.Appearance, these can be viewed here.

Advanced

For more advanced customisation, including defining your own indicator and bar styles please read here.

Getting In Touch

Please feel free to contact me on Twitter.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/MerrickSapsford/Tabman.

License

The library is available as open source under the terms of the MIT License.

tabman's People

Contributors

msaps 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.